Home > Software design >  Keras LSTM dimension value errors
Keras LSTM dimension value errors

Time:12-19

I have a problem about dimensions of LSTM. I have a matrix [168, 6, 7] as input. I want to get an output matrix sized [6, 7]. But I got this error:

ValueError: Input 0 of layer lstm is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 168, 6, 7)

What is the problem or how can I solve it? I tried also different input shapes, but I couldn't solve this problem.

model = Sequential()
model.add(LSTM(4, input_shape=(d1,d2),return_sequences = True))
model.add(Flatten())
model.add(Dense(d1*d2, activation="relu"))
model.add(Reshape((d1,d2)))
model.compile(optimizer= "Adam", loss="mse", metrics=["mse"])
model.fit(xtrain, ytrain, batch_size=100, epochs=100, verbose=1)

CodePudding user response:

Your LSTM layer needs 3D inputs shaped this way :

( number of observations , lenght of input sequence , number of features )

To learn more about it, it suggest you to take a look to this :

https://shiva-verma.medium.com/understanding-input-and-output-shape-in-lstm-keras-c501ee95c65e

  • Related