close

[Solved] ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 Error Occurs?

Today I get the following error ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 in python.

How To Solve ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 Error ?

  1. How To Solve ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 Error ?

    To Solve ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4 Error input_shape is supposed to be (timesteps, n_features). Remove the first dimension.

  2. ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4

Solution 1

I solved the problem by making

input size: (95000,360,1) and output size: (95000,22)

and changed the input shape to (360,1) in the code where model is defined:

model = Sequential()
model.add(LSTM(22, input_shape=(360,1)))
model.add(Dense(22, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
model.fit(ml2_train_input, ml2_train_output_enc, epochs=2, batch_size=500)

Solution 2

input_shape is supposed to be (timesteps, n_features). Remove the first dimension.

input_shape = (95000,360)

Same for the output.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read