Train selective branch of multi output keras model

Viewed 947

I have a multi output Keras model with a structure resembling this:

s = some_shared_layers()(input)
non_trainable1 = Dense(trainable=False) (s) 
non_trainable2 = Dense(trainable=False) (s) 
trainable = Dense() (s) 

model = Model(input, outputs=[non_trainable1, non_trainable2, trainable])

My model first computes a forward pass and uses the 1st 2 outputs to manipulate the input. It then computes another forward pass to get the 3rd output.

out1, out2,_ =model.predict(input_data) 
processed_data = foo(input_data, out1, out2) 
_,_, out3 = model.predict(processed_data)

How should I call model.fit() to train only the trainable layer? If I exclude the losses for the other outputs, Keras warns we will not be expecting any data to be passed to "non_trainable1" during training and excludes them from the computational graph.

Is there a better way to structure the model for this task?

1 Answers
Related