I want to to concatenate the last layer before the output of 2 trained models and have a new model that uses the merged layer to give predictions. below is the relevant parts of my code:
model1 = load_model("model1_location.model")
model2 = load_model("model1_location.model")
merged_model = Sequential(name='merged_model')
merged_model.add(merge([model1.layers[-1],model2.layers[-1]]))
merged_model.add(Dense(3, activation='softmax'))
The above code gives the following error:
ValueError: Layer merge_2 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.core.Dense'>.
What is the correct way to combine those models, Alternatively how do I get a symbolic tensor from a layer?
you need to get the output
attribute like so:
merged_model.add(merge([model1.layers[-1].output, model2.layers[-1].output]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With