使用keras训练时间序列lstm模型时遇到问题

时间:2019-06-01 16:38:19

标签: tensorflow machine-learning time-series lstm

我从this tutorial

运行了代码
# fit an LSTM network to training data
def fit_lstm(train, batch_size, nb_epoch, neurons):
    X, y = train[:, 0:-1], train[:, -1]
    X = X.reshape(X.shape[0], 1, X.shape[1])
    model = Sequential()
    model.add(LSTM(neurons, batch_input_shape=(batch_size, X.shape[1], X.shape[2]), stateful=True))
    model.add(Dense(1))
    model.compile(loss='mean_squared_error', optimizer='adam')
    for i in range(nb_epoch):
        model.fit(X, y, epochs=1, batch_size=batch_size, verbose=0, shuffle=False)
        model.reset_states()
    return model

然后我使用此模型进行训练

lstm_model = fit_lstm(train_scaled, 1, 3000, 4)

我遇到了问题

Expected int32, got tf.Variable 'lstm_2_W_i:0' shape=(1, 4) dtype=float32_ref of type 'Variable' instead.

我不知道如何解决它,有人可以帮忙吗?

0 个答案:

没有答案