Reputation: 410
I use 2 LSTM multilayer stack with dense layer it's showing me an error.
Here is my code :
model.add(LSTM(5, batch_input_shape=(batch_size, X.shape[1], X.shape[2]), stateful=True))
model.add(Dropout(0.2))
model.add(LSTM(5,return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(units=1))
model.add(Activation('relu'))
batch_input_shape=(1,1,4)
It's showing me following error:
ValueError: Input 0 is incompatible with layer lstm_57: expected ndim=3, found ndim=2
Upvotes: 1
Views: 1606
Reputation: 569
Your second LSTM admits input of shape [batch_size, time_steps, features]
. The first LSTM yields outputs of shape [batch_size, output_units]
, since the parameter return_sequences
defaults to False
.
You need to explicitly set return_sequences = True
in your first LSTM to render the two recurrent layers compatible.
Upvotes: 2