Python ValueError:输入0与层lstm_55不兼容:预期ndim=3,发现ndim=2
我使用了2层LSTM多层叠加和致密层,这显示了一个错误。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
这是我的密码:
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