Damares Oliveira
Damares Oliveira

Reputation: 143

How to concatenate ResNet50 hidden layer with another model input?

I am trying to concatenate the output of a hidden layer in ResNet with the input of another model but I get the following error:

ValueError: Output tensors to a Model must be the output of a Keras Layer (thus holding past layer metadata)

I am using the Concatenate layer from Keras as recommended in How to concatenate two layers in keras?, however it did not work. What may I be missing? Do I have to add a dense layer to it too? The idea is not to change the second input until it is concatenated with the first input (the merged input will be an input of a third model).

resnet_features = resnet.get_layer('avg_pool').output
model2_features = Input(shape=(None, 32))
all_features = Concatenate([resnet_features, model2_features])

mixer = Model(inputs=[resnet.input, model2_features], 
                             outputs=all_features)

Upvotes: 0

Views: 1261

Answers (1)

Anna Krogager
Anna Krogager

Reputation: 3588

It looks like you are missing two brackets at your concatenation layer. It should look like this:

all_features = Concatenate()([resnet_features, model2_features])

Moreover, you have to make sure that the shapes of resnet_features and model2_features are the same except for the concatenation axis since otherwise you won't be able to concatenate them.

Upvotes: 2

Related Questions