I trained a FCNN model using tensorflow with keras backend. The model consists of two separate networks (trained in same graph).
Two mid-layers of this model has same shape ((?,512, 24, 16), 'channel_first'). I would like to extract these two layers (based on 2nd response Keras, How to get the output of each layer?) and map them to each other using a dense layer:
intermediate_layer_net = Model(inputs=model.input,
outputs=model.get_layer(name='net1_bn7').output)
intermediate_layer_net2 = Model(inputs=model.input,
outputs=model.get_layer(name='net2_bn5').output)
mid_model_in = Input(shape=(512, 24, 16))
mid_model_dense = Dense(512,activation=None, use_bias=True, kernel_initializer="glorot_uniform", bias_initializer="zeros", kernel_regularizer=None, bias_regularizer=None, activity_regularizer=None, name='mid_dense')(mid_model_in)
mid_model = Model(inputs=[mid_model_in], outputs=[mid_model_dense])
mid_model.compile(loss=['mean_squared_error'], optimizer='Adam', metrics=['mae'])
history_mid= mid_model.fit(intermediate_layer_net, intermediate_layer_net2, batch_size=10, epochs=50, validation_split=0.2, shuffle=True)
When I run the code above I get this error: AttributeError: 'Model' object has no attribute 'shape'
how do I pass the shape? shouldn't the shape be included from the first model from which I extract the output layer?