python - ValueError:输入 0 与层 lstm_55 不兼容:预期 ndim=3,发现 ndim=2
问题描述
我使用 2 个 LSTM 多层堆栈和密集层,它向我显示了一个错误。
这是我的代码:
model.add(LSTM(5, batch_input_shape=(batch_size, X.shape[1], X.shape[2]), stateful=True))
model.add(Dropout(0.2))
model.add(LSTM(5,return_sequences=False))
model.add(Dropout(0.2))
model.add(Dense(units=1))
model.add(Activation('relu'))
batch_input_shape=(1,1,4)
它向我显示以下错误:
ValueError: Input 0 is incompatible with layer lstm_57: expected ndim=3, found ndim=2
解决方案
您的第二个 LSTM 允许输入 shape [batch_size, time_steps, features]
。第一个 LSTM 产生 shape[batch_size, output_units]
的输出,因为参数return_sequences
默认为False
。
您需要return_sequences = True
在第一个 LSTM 中显式设置以使两个循环层兼容。
推荐阅读
- sql-server - SQL 首先检查列名而不是条件,并给我一个错误无效的列名。如何解决这个问题?
- c# - 模型更新后未设置属性
- networking - Kubernetes 集群中是否可以有隔离的网络?
- javascript - html中的图像隐藏在标题的导航栏下
- jquery - jquery如何获取image和div的交集数据
- paypal - 我可以在 PayPal Gateway 中使用 Braintree SDK(特别是我需要 Apple Pay)吗?
- html - 如何使我的导航栏菜单按钮工作?
- android - 如何在 Android 中制作日历网格
- fluent-assertions - 仅断言没有值的 json .Net 对象属性名称
- java - 修复 java.lang.module.ResolutionException:两个模块将同一个包导出到非模块化应用程序中的另一个模块