Let’s say I have a model, which has 2 inputs. The first input is a number, and the second input is another number, which in reality is a class.

This model is split into 2 submodels. First sub-model works on the input, and the second sub-model works on the output of the first sub-model.

The value of the first input will very greatly by the output of the second. Thus, I wish to be able to have multiple candidates of the first sub-model, and dynamically select which one to use at each step, both during training and inference, based on the value (class) of the second input.

I did not manage to achieve this. I tried using the tf.cond, the tf.switch_case and several other things, but I never managed. When I asked chat GPT it said I should be using PyTorch for this. Is there really no way to do this ?

  • work_account_mpOPB
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    I’m not sure what you mean to be honest. I have a model where the first part is a submodel that is then used later on in the main model. Since there are different behaviour patterns here depending on the category (second input) i was wondering if it would be possible to have say 4 submodels corresponding with 4 classes, and use the corresponding one both during training when updating weights, and also during inference.

    something like

    value = Input()
    categ = Input()
    
    dense0, dense1 = Dense(5), Dense(5)
    
    if categ == 0:
        first_layer = dense0
    else:
        first_layer = dense1
    
    # use first_layer accordingly...