首页 > 解决方案 > keras中的输入形状RNN

问题描述

我是 Keras 的新手,我正在尝试创建我的网络,这是一个具有 2 个功能的时间序列数据。以下是我的训练输入和输出的详细信息:

train_input.shape= (1, 21, 20) (21 time-step, 20 (2*10) 10 training-set with each 2 features)

train_output.shape = (1, 21, 10) 

这是代码:

model = keras.models.Sequential([
    keras.layers.SimpleRNN(4 ,input_shape = (trainset.shape[1],2), return_sequences=True, use_bias= False, activation = "tanh"), 
    keras.layers.TimeDistributed(keras.layers.Dense(1))])  
print(model.get_weights())
model.compile(loss= "mean_squared_error" , optimizer= keras.optimizers.SGD(), metrics = ['mse'])
saved_files="\\RNN_based_statespace\\models\\weights-{epoch:02d}-{val_loss:.6f}.hdf5"
checkpoint = keras.callbacks.ModelCheckpoint(saved_files, monitor='val_loss', verbose=0, save_best_only=True, save_weights_only=True, mode='auto', period=1)
callbacks_list = [checkpoint]
history = model.fit(trainset , output_train, epochs = 100, batch_size=1 , validation_data = (validationset,output_valid), callbacks=[callbacks_list]
Prediction = model.predict(testset)
      

但我得到了错误:

ValueError: Input 0 is incompatible with layer sequential_1: expected shape=(None, None, 2), found shape=[1, 21, 20]

如何传递正确的参数?

标签: pythonkerasrecurrent-neural-network

解决方案


推荐阅读