How To Fix: Valueerror: Input 0 Is Incompatible With Layer Lstm_2: Expected Ndim=3, Found Ndim=2
I have a question concerning time series data. My training dataset has the dimension (3183, 1, 6) My model: model = Sequential() model.add(LSTM(100, input_shape = (training_input_d
Solution 1:
The problem is that the first LSTM layer is returning something with shape (batch_size, 100)
. If you want to iterate with a 2nd LSTM layer, you should probably add the option return_sequences=True
in the first LSTM layer (which would then return an object of shape (batch_size, training_input_data.shape[1], 100)
.
Note that passing input_shape = (..)
in the 2nd LSTM is not mandatory, as the input shape of this layer is autoamtically computed based on the output shape of the first one.
Solution 2:
You need to set parameter return_sequences=True to stack LSTM layers.
model = Sequential()
model.add(LSTM(
100,
input_shape = (training_input_data.shape[1], training_input_data.shape[2]),
return_sequences=True
))
model.add(Dropout(0.2))
model.add(LSTM(100, input_shape = (training_input_data.shape[1], training_input_data.shape[2])))
model.add(Dense(1))
model.compile(optimizer = 'adam', loss='mse')
See also How to stack multiple lstm in keras?
Post a Comment for "How To Fix: Valueerror: Input 0 Is Incompatible With Layer Lstm_2: Expected Ndim=3, Found Ndim=2"