How to run ml model depending on if-else statement from previous model

Viewed 26

I am working with high imbalanced classes at task of classifying images. I want to know if it is possible to create the architecture where we firstly trying to decide if this image belongs to targeted class (like trees) with model_A. If no then we don`t work with this image anymore, if yes then this img becomes an input for the next model_B and we get demanded output (like is the tree a palm tree or not). I want to something like that:

pred_1 = model_A.predict(x)
if pred_1 == '2':
    pred_2 = model_B.predict(x)
else:
    doNothing()

And other questions:

  1. How to do it if I need to combine these models to one model? For ex., with some kind of Pipeline: GeneralPipe = Pipeline(model_A, if condition=='2' then model_B)
  2. Could you share some examples of code/articles please?

I`ve attached the link of general illustration of my idea: https://i.stack.imgur.com/KrJDw.png

0 Answers
Related