Multiple output single loss model

Viewed 152

I have model subclassing the tensorflow.keras.models.Model class. The call method returns [output_1, ouput_2], where output_1 and output_2 have different shapes. How can I pack both outputs to be used on the same loss function? (Have y_pred on the custom loss be the list returned by the call method)

1 Answers

Do you necessarily need the neural net output to be 2 separate outputs?

Instead, you could combine them into one output and then separate them out later once you are using the data in the rest of your application. To combine them, use a tf.keras.layers.concatenate layer after your last layers, which will combine your 2 outputs into 1. That way, the only 1 vector needs to be passed to the loss function.

Related