Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:输入0与层lstm_55不兼容:预期ndim=3,发现ndim=2_Python_Keras_Lstm - Fatal编程技术网

Python ValueError:输入0与层lstm_55不兼容:预期ndim=3,发现ndim=2

Python ValueError:输入0与层lstm_55不兼容:预期ndim=3,发现ndim=2,python,keras,lstm,Python,Keras,Lstm,我使用了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.a

我使用了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'))
它向我显示了以下错误:

ValueError: Input 0 is incompatible with layer lstm_57: expected ndim=3, found ndim=2

您的第二个LSTM允许输入形状
[批次大小、时间步数、特征]
。由于参数
返回序列
默认为
,因此第一个LSTM产生形状
[批次大小,输出单位]


您需要在第一个LSTM中显式设置
return\u sequences=True
,以使两个重复层兼容

将此添加到第一层
return\u sequences=True
ValueError: Input 0 is incompatible with layer lstm_57: expected ndim=3, found ndim=2