Discussions>Stack multiple keras lstm layers>

Stack multiple keras lstm layers

I'm using Keras 2.1.* and want to stack multiple keras lstm layers into one model.

I was trying something like this.

model = Sequential()
model.add(LSTM(10, input_shape =(n, s)))

but it didn't work and I get the following error.

Exception: Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2
3 votesLP235.00
1 Answers

It's just because you are using it wronlgy.

The input shape should be: (batch_size, timesteps, data_dim) and you have to put return_sequences=True for the first layer.

Here is how it looks like

# shape: (batch_size, n, s)
model = Sequential()
model.add(LSTM(10, return_sequences=True,
               input_shape=(n, s)))
model.add(LSTM(10, return_sequences=True))
model.add(Dense(1, activation='sigmoid'))

Also there is another discussion with the same issue. Take a look at it.

Input 0 is incompatible with layer lstm

Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?