When I try to add a second LSTM layer to my model I get the following error message: "Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2".
I also get the same message when return_sequences is set to True. I would like it to be True, but it only works when set to False. I have tried Keras Reshape with no luck.
Any help would be greatly appreciated, thanks!
# X is a 3D array with roughly 1000 2D arrays of size (n_steps, n_features)
X = X.reshape((X.shape[0], X.shape[1], n_features))
# setup model
model = Sequential()
lstmSize = 32
dropout = 0.2
denseSize = 1
returnSequences = False # doesn't work when set to True
model.add(LSTM(lstmSize, activation='relu', return_sequences=returnSequences, input_shape=(n_steps, n_features)))
model.add(Dropout(dropout))
model.add(LSTM(lstmSize, activation='relu', return_sequences=returnSequences, input_shape=(n_steps, n_features))) # error here
model.add(Dropout(dropout))
model.add(Dense(denseSize, activation='softmax'))
model.compile(optimizer='adam', loss='mse')
model.fit(X, y, batch_size=None, epochs=700, verbose=0)
The output works when I only have 1 LSTM layer or return_sequences = False but gives the error 'Input 0 is incompatible with layer lstm_2: expected ndim=3, found ndim=2' otherwise.