在运行我的模型一个时期后,它崩溃并显示以下错误消息:
InvalidArgumentError:从形状为 [56,9] 的张量指定形状为 [60,9] 的列表
[[{{节点 TensorArrayUnstack/TensorListFromTensor}}]]
[[sequential_7/lstm_17/PartitionedCall]] [操作:__inference_train_function_29986]
这是在我将 LSTM 层更改为stateful=True
并且必须通过
这batch_input_shape
参数而不是input_shape
下面是我的代码,我确信它与我的数据的形状有关:
test_split = 0.2
history_points = 60
n = int(histories.shape[0] * test_split)
histories_train = histories[:n]
y_train = next_values_normalized[:n]
histories_test = histories[n:]
y_test = next_values_normalized[n:]
next_values_test = next_values[n:]
print(histories_train.shape)
print(y_train.shape)
-->(1421, 60, 9)
-->(1421, 1)
# model architecture
´´´model = Sequential()
model.add(LSTM(units=128, stateful=True,return_sequences=True, batch_input_shape=(60,history_points, 9)))
model.add(LSTM(units=64,stateful=True,return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(units=32))
model.add(Dropout(0.2))
model.add(Dense(20))
ADAM=keras.optimizers.Adam(0.0005, beta_1=0.9, beta_2=0.999, amsgrad=False)
model.compile(loss='mean_squared_error', optimizer=ADAM)
model.fit(x=histories_train, y=y_train, batch_size=batchsize, epochs=50, shuffle=False, validation_split=0.2,verbose=1)
´´´