python - ValueError : Input 0 is incompatible with layer lstm_13: expected ndim=3, 发现 ndim=4

标签 python keras lstm recurrent-neural-network

我正在尝试多类分类,这里是我的训练输入和输出的详细信息:

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

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 in line: model.add(LSTM(22, input_shape=(1, 95000,360)))

请帮帮我,我无法通过其他答案解决。

最佳答案

我通过制作解决了这个问题

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

并在定义模型的代码中将输入形状更改为 (360,1):

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)

关于python - ValueError : Input 0 is incompatible with layer lstm_13: expected ndim=3, 发现 ndim=4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44583254/

相关文章:

python - 重试 <Response [404]> 直到我得到 <Response [200]>

python - 对行进行排序并删除 NaN 值

machine-learning - 在 LSTM 中使用 tanh 的直觉是什么?

tensorflow - 在 Tensorflow 中构建 LSTM RNN 时维度不匹配

python - Keras CuDNNLSTM 隐式激活函数?

machine-learning - 我们应该何时何地使用这些 keras LSTM 模型

python - 无法连接到 Docker 容器上的 neo4j 数据库

python - Numpy 数组 : Changing the values of the last column when lines of a 2d-array are equal to lines of another 2d-array

tensorflow - 在 Keras 上训练时,有没有办法调试张量内的值?

tensorflow - 如何修复 "Invalid argument: Key: feature. Can' t 解析序列化示例。”