问题描述
我正在尝试多类分类,这里是我的训练输入和输出的详细信息:
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 长度的输入数组,每个元素是一个长度为 360 的数组)
train_output.shape = (1, 95000, 22)(有 22 个类)
train_output.shape = (1, 95000, 22) (22 Classes are there)
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)
错误是:
ValueError: Input 0 is incompatible with layer lstm_13: expected ndim=3, found ndim=4排队:model.add(LSTM(22, input_shape=(1, 95000,360)))
请帮帮我,我无法通过其他答案解决.
Please help me out, I am not able to solve it through other answers.
推荐答案
我通过制作
输入大小:(95000,360,1) 和输出大小:(95000,22)
并在定义模型的代码中将输入形状更改为 (360,1):
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)
这篇关于ValueError:输入 0 与层 lstm_13 不兼容:预期 ndim=3,发现 ndim=4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!