a819411321
2018-11-05 07:36
采纳率: 100%
浏览 12.3k
已采纳

LSTM输入数据格式问题

输入样本train_x1 标签train_y1
样本与标签都是(20000,10)
然后我reshape变成三维(20000,1,10)报错 求该如何修改格式
输入十个数值,输出十个数值。

train_x1 = np.reshape(train_x1, (train_x1.shape[0],1,train_x1.shape[1]))
train_y1 = np.reshape(train_y1, (train_y1.shape[0],1,train_y1.shape[1]))

model = Sequential()

model.add(LSTM(50, input_shape=(train_x1.shape[1], train_x1.shape[2])))

model.add(Dense(10))

model.compile(loss='mse', optimizer='adam')

model.fit(train_x1, train_y1, nb_epoch = 300, batch_size = 10)

model.save_weights('LSTM.model')

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • threenewbee 2018-11-05 08:38
    已采纳

    model.add(LSTM(50, input_shape=(train_x1.shape[1], train_x1.shape[2])))
    ->
    model.add(LSTM(50, input_shape=(train_x1.shape[0],, train_x1.shape[1], train_x1.shape[2])))

    或者还有一个办法就是不用input_shape,而是指定下timesteps=1

    具体看下keras的文档。

    1 打赏 评论
  • weixin_42186194 2019-01-04 18:27

    你好 可以看下你这个前面的代码吗?

    1 打赏 评论

相关推荐 更多相似问题