【问题标题】:Input 0 is incompatible with layer lstm_16: expected ndim=3, found ndim=2?输入 0 与层 lstm_16 不兼容:预期 ndim=3,发现 ndim=2?
【发布时间】:2019-11-07 03:41:36
【问题描述】:

我收到错误Input 0 is incompatible with layer lstm_16: expected ndim=3, found ndim=2,代码如下:

#Step 6: Initialize the RNN
regressor = Sequential()

#Step 7: Adding the LSTM layers and some Dropout regularization

#Dropout regularization: drops out unnecessary data, so we are not shifting huge amounts of data through the network

#Adding the first LSTM layer and some Dropout regularization
#units - dimensionality in output space
regressor.add(LSTM(units = 50, return_sequences = True, input_shape = (X_train.shape[1], 1)))

#Adding the second LSTM layer and some Dropout regulariation
regressor.add(LSTM(units = 25, return_sequences = True))
regressor.add(Dropout(0.2))

#Adding a third LSTM layer and some Dropout regularization
regressor.add(LSTM(units = 12, return_sequences = True))
regressor.add(Dropout(0.2))

#Adding a fourth LSTM layer and some Dropout regularization
regressor.add(LSTM(units = 6))
regressor.add(Dropout(0.2))

#Step 8: Adding the output layer
regressor.add(Dense(units = 1))

X_train 的尺寸为(114, 1, 216)(我电脑时产生的X_train.shape)。为什么会出现此错误?

【问题讨论】:

  • 这是什么数据?

标签: python tensorflow keras lstm recurrent-neural-network


【解决方案1】:

在这里,您在第一个 LSTM 层的 input_shape 中传递两个值。

Keras LSTM 接受并输入 (samples, time_steps, nfeatures) 的形状,并且您的图层输入必须具有此形状。

【讨论】:

    猜你喜欢
    • 2020-06-12
    • 1970-01-01
    • 2020-10-05
    • 2022-08-15
    • 2019-06-04
    • 2019-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多