Combine two model in tensorflow

Skip to first unread message

Soumya Mishra

Mar 24, 2020, 9:29:01 AM3/24/20
to TensorFlow Hub
Hi All,
       I have two models say M1 & M2 both are written in Tensorflow.The output of M1 is given as input to M2 and every time gradient is calculated it should be back propagated till M1's input.Please help me with this issue.

Biswajit Sahoo

Mar 26, 2020, 1:23:59 PM3/26/20
to TensorFlow Hub
You can use functional API of Tensorflow(keras) to solve this problem. The following pseudo code might help.

inputs = tf.keras.Input(input_shape = ...)        # Specify input shape
output_1 = M1(inputs)
output_2 = M2(output_1)
new_model = tf.keras.Model(inputs = inputs, outputs = output_2)
new_model.summary( )  # Verify your total trainable parameters


Hope this will solve your issue.
Reply all
Reply to author
0 new messages