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

I am trying to categorize multiple classes, and here are the details of my training input and output:

train_input.shape = (1, 95000, 360) (length of array of length 95000 with each element is an array of length 360)

train_output.shape = (1, 95000, 22) (there are 22 classes)

model = Sequential()

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

      

Mistake:

ValueError: Input 0 is incompatible with layer lstm_13: expected ndim = 3, found ndim = 4 in queue: model.add (LSTM (22, input_shape = (1, 95000,360)))

Please help me, I cannot solve this via other answers.

+3


source to share


2 answers


I solved the problem by doing

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



and changed the input form to (360,1) in the code where the 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)

      

+3


source


input_shape must be (timesteps, n_features). Delete the first dimension.

input_shape = (95000,360)

      



The same goes for the output.

-1


source







All Articles