keras lstm输入形状错误请帮助:(

时间:2019-11-11 14:42:34

标签: keras lstm

您好,我正在尝试创建用于预测值的lstm:(

但我认为我对使用角膜维数的理解有局限性

我需要帮助

我的代码如下


train_data

train = train.to_numpy()
train = train.reshape(train.shape[0], 1, train.shape[2])
target_load = target_load.iloc[:].values

np.shape(train), np.shape(target_load)

dataShapes for train and answer

from keras import optimizers
from keras.models import Model, Sequential
from keras.layers import Input, Dense, LSTM, Bidirectional, Dropout

xInput = Input(shape=(1,7))
xLstm_1 = LSTM(128, return_sequences=True)(xInput) 
xLstm_1 = Dropout(0.2)(xLstm_1)
xLstm_2 = Bidirectional(LSTM(128))(xLstm_1)
xOutput = Dense(1)(xLstm_2)

ada = optimizers.Adam(lr=0.001)

model = Model(train, target_load)
model.compile(loss='mean_squared_error', optimizer=ada)

model.summary()

errors

1 个答案:

答案 0 :(得分:0)

检查TensorFlow的API:https://www.tensorflow.org/api_docs/python/tf/keras/Model

必须使用符号张量实例化模型对象:

tf.keras.Model(inputs=inputs, outputs=outputs)`

在您的情况下是

model = Model(inputs = xInput, outputs = xOutput)