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

前端 未结 4 1273
甜味超标
甜味超标 2020-12-14 17:40

I am trying for multi-class classification and here are the details of my training input and output:

train_input.shape= (1, 95000, 360) (95000 length

相关标签:
4条回答
  • 2020-12-14 18:10

    Well, I think the main problem out there is with the return_sequences parameter in the network.This hyper parameter should be set to False for the last layer and true for the other previous layers.

    0 讨论(0)
  • 2020-12-14 18:13

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

    input_shape = (95000,360)
    

    Same for the output.

    0 讨论(0)
  • 2020-12-14 18:14

    return_sequences should not be set True in all layers, just do not set it in the last layer, and omit return_sequences=True

    0 讨论(0)
  • 2020-12-14 18:23

    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)
    
    0 讨论(0)
提交回复
热议问题