本文介绍了如何解决:ValueError:输入0与lstm_2层不兼容:预期的ndim = 3,找到的ndim = 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对时间序列数据有疑问.我的训练数据集的维度为(3183,1,6)

I have a question concerning time series data. My training dataset has the dimension (3183, 1, 6)

我的模特:

model = Sequential()
model.add(LSTM(100, input_shape = (training_input_data.shape[1], training_input_data.shape[2])))
model.add(Dropout(0.2))
model.add(LSTM(100, input_shape = (training_input_data.shape[1], training_input_data.shape[2])))
model.add(Dense(1))
model.compile(optimizer = 'adam', loss='mse')

在第二个LSTM层出现以下错误:

I get the following error at the second LSTM layer:

推荐答案

您需要设置参数return_sequences = True才能堆叠LSTM层.

You need to set parameter return_sequences=True to stack LSTM layers.

model = Sequential()
model.add(LSTM(
    100,
    input_shape = (training_input_data.shape[1], training_input_data.shape[2]),
    return_sequences=True
))
model.add(Dropout(0.2))
model.add(LSTM(100, input_shape = (training_input_data.shape[1], training_input_data.shape[2])))
model.add(Dense(1))
model.compile(optimizer = 'adam', loss='mse')

另请参见如何在keras中堆叠多个lstm?

这篇关于如何解决:ValueError:输入0与lstm_2层不兼容:预期的ndim = 3,找到的ndim = 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:01