python - 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]
如何传递正确的参数?
解决方案
推荐阅读
- asp.net - 需要帮助识别数据库模式中的关联
- google-analytics - 如何使用记分卡从 Google Data Studio 中的 2 个不同页面划分用户数量?
- c# - Linq 语句中的“对象引用未设置为对象的实例”
- python - 尝试使用 smtplib 和 email.mime.multipart 从 python 发送电子邮件,收到错误“'Series' object has no attribute 'encode'”
- python - 从字典中打印值而不重复?
- android - PorterDuff.Mode.CLEAR 在画布上绘制黑色
- javascript - 反应原生 upi 付款被拒绝
- flutter - 如何仅在 Sqlite(或 Flutter 中的 sqflite)中获取今天的记录?
- javascript - 无法读取未定义的属性“排序”
- reactjs - 在 reactjs 中本地运行 webpack