Sikai Yao
Sikai Yao

Reputation: 327

How to use Concatenate layers in keras?

My code like this:

balabala...
conv_model.add(keras.layers.Flatten())

input2 = keras.models.Sequential()
input2.add(keras.layers.Activation('linear', input_shape=(1,)))

model = keras.models.Sequential()
model.add(keras.layers.Merge([conv_model, input2], mode='concat'))
balabala.....

When I run this code, it says:

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.

I have tried to use 'keras.layers.Concatenate' in many ways like:

model.add(keras.layers.Concatenate([conv_model, angle]))

But it says:

The first layer in a Sequential model must get an `input_shape` or 
`batch_input_shape` argument

Is anybody can help?

Upvotes: 0

Views: 3150

Answers (1)

Daniel Möller
Daniel Möller

Reputation: 86600

Sequential models are not supposed to work with branches.

You need a functional API model.

input2 = Input((1,))
out2 = Activation('linear')(input2) 

concatenated = Concatenate(axis=chooseOne)([conv_model.output,out2])

model = Model([conv_model.input,input2], concatenated)

PS: the layer Activation('linear') does absolutely nothing in any model.

Upvotes: 1

Related Questions