I want to merge two sequential models in sum mode into one model using keras as:

left = Sequential()
right = Sequential()
model = Sequential()
model.add(Add()([left, right]))

But the statement model.add(Add()[left,right]) gives error: Layer add was called with an input that isn't a symbolic tensor. Received type: . Full input: [, ]. All inputs to the layer should be tensors.


The error says what's the problem: the method expects a Tensors, but you are giving a Sequential model object.

Use functional model (from keras.models import Model), not Sequential.

Then, merge the models with:

merged_models = Model(inputs=[first_model_input, second_model_input], outputs=[first_model_output, second_model_output])

or whatever your input looks like.

  • $\begingroup$ In my case, I need to pass the output of Add() to next layers after merging. For example Dense. If I use: merged_models = Model(inputs=[left.input, right.input], outputs=[left.output,right.output]) dd=Dense(dm, activation='linear')(merged_models.output) It again gives error that dense was expecting one input but it got two. Does this mean that the output of Model is not merging them $\endgroup$ Mar 29 '19 at 10:01
  • $\begingroup$ Then your approach (and the question) is wrong. Just don't create the models while you are not finished with defining all the layers. That way you won't get errors about expecting the Tensors, but something else was given. And then create the model at the end. $\endgroup$ Mar 29 '19 at 10:03
  • $\begingroup$ Does this mean that the output of Model is not merging them Yes, the model is not merging the outputs, that's not the purpose of Functional model constructor. To merge the layers, use layers, not model constructor. $\endgroup$ Mar 29 '19 at 10:06

I created a similar model with the functional api:

leftInput = keras.layers.Input((10, 10))
left = keras.layers.LSTM(64, activation='sigmoid')(leftInput)
rightInput = keras.layers.Input((10, 10))
right = keras.layers.LSTM(64, activation='sigmoid')(rightInput)
output = keras.layers.Add()([left, right])
model = keras.Model(inputs=[leftInput, rightInput], outputs=output)

I don't know the specifics of your model but this should also work for your problem.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.