【发布时间】:2018-04-29 07:34:44
【问题描述】:
我正在尝试向我的神经网络添加更多 LSTM 层,但我不断收到以下错误:
ValueError: Error when checking target: expected dense_4 to have 2 dimensions, but got array with shape (385, 128, 1)
我的模型代码如下:
model = Sequential()
model.add(LSTM(60, return_sequences=True, input_shape=(128, 14)))
model.add(LSTM(60, return_sequences=False))
model.add(Dense(1))
model.compile(loss='mean_squared_error', optimizer='adam')
model.fit(data_train, RUL_train, epochs=number_epochs, batch_size=batch_size, verbose=1)
当我删除第二个 LSTM 层时它工作正常。或者,如果我添加更密集的层。只是在我添加 LSTM 层时没有。 RUL_train 的形状为 (385, 128, 1)。 model.summary 的输出如下:
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
lstm_15 (LSTM) (None, 128, 60) 18000
_________________________________________________________________
lstm_16 (LSTM) (None, 60) 29040
_________________________________________________________________
dense_7 (Dense) (None, 1) 61
=================================================================
Total params: 47,101
Trainable params: 47,101
Non-trainable params: 0
_________________________________________________________________
任何帮助表示赞赏。
【问题讨论】:
-
您使用的是哪个版本的 Keras?
-
return_sequences=True在最后一层