Input 0 is incompatible with layer lstm: expected ndim=3, found ndim=2 in Keras

I'm using Keras 2.2 LSTM and want to build a recurrent network, but I can't find the reason of this error. Here is the code

 model=Sequential()

 model.add(LSTM(16, return_sequences=True, activation='relu'))
 model.add(LSTM(16, activation='relu'))

 model.add(Dense(32, activation='relu'))
 model.add(Dropout(0.3))

 model.add(Dense(10, activation='softmax'))


 model.compile(optimizer='adam',
          loss='mean_squared_error',
          metrics=['accuracy'])

 Net = model.fit(x_train, y_train, batch_size=32, epochs=40)

I'm still getting this issue

ValueError: Input 0 is incompatible with layer lstm: expected ndim=3, found ndim=2

Any ideas about this?

keraslstm
4 votesJO218.00
1 Answers
JW229.00
4

There are 2 main points related to your issue

  1. Keras LSTM takes and input with shape of (n_examples, n_times, n_features) and your layers input has to have this shape
  2. You will have to put return_sequences=True for the second LSTM layer as well
Reply
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?