有状态双向LSTM批处理大小问题

时间:2018-10-31 19:51:39

标签: python tensorflow keras lstm

我正在尝试实现有状态的双向LSTM,但是我仍然收到以下错误:

“无法为形状为'(96,24,8)的Tensor'bidirectional_18_input:0'输入形状(72,24,8)的值

这是我的代码:

mdl = Sequential()
# create and fit the LSTM network
mdl.add(Bidirectional(LSTM(12 ,return_sequences=True, stateful=True),batch_input_shape=(96, lags, n_features )))
mdl.add(Bidirectional(LSTM(7,stateful=True)))
mdl.add(Dense(12))
mdl.add(Dense(12))
mdl.add(Dense(1))


mdl.compile(loss='mean_squared_error', optimizer='adam')

# early stopping implementation
filepath="weights.best.hdf5"
checkpoint = ModelCheckpoint(filepath, monitor='val_loss', verbose=1, save_best_only=True, mode='min')
early_stop = EarlyStopping(monitor='val_loss', patience=200, mode='min') 
callbacks_list = [checkpoint, early_stop]


# fit network
print(mdl.summary())

for i in range(100):
    mdl.fit(X_train, y_train, epochs=1, batch_size=96, validation_data=(X_test, y_test), verbose=2, shuffle=False,
                   callbacks=callbacks_list)
    mdl.reset_states()

我具有以下架构: enter image description here

我不明白为什么即使我使用的批次大小为96,我仍在输入形状值(72,24,8)

0 个答案:

没有答案