I am trying to merge two networks. I can accomplish this by doing the following:
merged = Merge([CNN_Model, RNN_Model], mode='concat')
But I get a warning:
merged = Merge([CNN_Model, RNN_Model], mode='concat')
__main__:1: UserWarning: The `Merge` layer is deprecated and will be removed after 08/2017. Use instead layers from `keras.layers.merge`, e.g. `add`, `concatenate`, etc.
So I tried this:
merged = Concatenate([CNN_Model, RNN_Model])
model = Sequential()
model.add(merged)
and got this error:
ValueError: The first layer in a Sequential model must get an `input_shape` or `batch_input_shape` argument.
Can anyone give me the syntax as how I would get this to work?
Don't use sequential models for models with branches.
Use the Functional API:
from keras.models import Model
You're right in using the Concatenate
layer, but you must pass "tensors" to it. And first you create it, then you call it with input tensors (that's why there are two parentheses):
concatOut = Concatenate()([CNN_Model.output,RNN_Model.output])
For creating a model out of that, you need to define the path from inputs to outputs:
model = Model([CNN_Model.input, RNN_Model.input], concatOut)
This answer assumes your existing models have only one input and output each.