Keras LSTM 维度值错误
Keras LSTM dimension value errors
我对 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)
您的 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
我对 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)
您的 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