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)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.