python - Stack two LSTM layers in Keras dimension mismatch
问题描述
I want to make an LSTM neural net using Keras which gets as input some length of four features and predicts 10 following values. And I can't manage to set proper input dimensions. X_train
is an array of shape (34,5,4) (repeated observations, the sequence of observations, features) y_train
is an array of shape(34,10). I can't manage to satisfy the required dimensions.
Any ideas what am I doing wrong?
X_train = X_train.reshape((X_train.shape[0], X_train.shape[1], 4))
model.add(LSTM(30, dropout=0.2, batch_size=window_size))
model.add(LSTM(10, activation=None))
model.compile(optimizer='adam',loss='mse')
model.fit(X_train,y_train,epochs= epochs,validation_split=0.2,shuffle=True)
解决方案
如果要堆叠两层lstm
,则需要return_sequence
用于第一层,它返回每个时间步的输出,将馈送到第二lstm
层。
这是解释示例,您可以通过它解决您的问题。
推荐阅读
- javascript - 提交summernote文本区域时出现验证错误
- mongodb - 新承诺不允许来自 mongo 回调的所需类型
- javascript - 将本地 JSON 数据呈现到 Tabulator 表中
- http - 数据库用户被阻止时的 REST HTTP 状态码
- gradle - 如何将依赖项添加到 kotlinCompilerClasspath?
- javascript - Javascript 解析 HTML 并查找元素
- mysql - 用这种方式不存在的数据扩展结果
- excel - 检查线程注释
- vba - 将公式转换为字符串
- javascript - dirty-chai.js 到底是做什么的?