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

问题描述 投票:0回答:1

我使用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'))
batch_input_shape=(1,1,4)

它向我显示以下错误:

ValueError: Input 0 is incompatible with layer lstm_57: expected ndim=3, found ndim=2
python keras lstm
1个回答
0
投票

你的第二个LSTM承认形状[batch_size, time_steps, features]的输入。第一个LSTM产生形状[batch_size, output_units]的输出,因为参数return_sequences默认为False

您需要在第一个LSTM中明确设置return_sequences = True以使两个复现层兼容。

© www.soinside.com 2019 - 2024. All rights reserved.