【问题标题】:Keras LSTM dimension value errorsKeras LSTM 维度值错误
【发布时间】:2022-01-20 22:10:58
【问题描述】:

我对 LSTM 的维度有疑问。我有一个矩阵 [168, 6, 7] 作为输入。我想得到一个大小为 [6, 7] 的输出矩阵。但是我收到了这个错误:

ValueError: Input 0 of layer lstm is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 168, 6, 7)

是什么问题或我该如何解决?我也尝试了不同的输入形状,但我无法解决这个问题。

model = Sequential()
model.add(LSTM(4, input_shape=(d1,d2),return_sequences = True))
model.add(Flatten())
model.add(Dense(d1*d2, activation="relu"))
model.add(Reshape((d1,d2)))
model.compile(optimizer= "Adam", loss="mse", metrics=["mse"])
model.fit(xtrain, ytrain, batch_size=100, epochs=100, verbose=1)

【问题讨论】:

    标签: python tensorflow keras lstm


    【解决方案1】:

    您的 LSTM 层需要以这种方式成形的 3D 输入:

    ( number of observations , lenght of input sequence , number of features )
    

    要了解更多信息,建议您看一下:

    https://shiva-verma.medium.com/understanding-input-and-output-shape-in-lstm-keras-c501ee95c65e

    【讨论】:

      猜你喜欢
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-21
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 2018-02-10
      相关资源
      最近更新 更多