我有一个数据集,其中包括4个温度传感器在建筑物内/外测量的不同位置:
我正在训练一个模型,该模型将形状为(96, 4)的输入作为四个传感器的96个时间步长。我想要预测未来每个传感器的48个点,形状为(48, 4)。
到目前为止,我已经实现了一种只能预测一个传感器的方法,并且大多数是按照TensorFlow教程中的这一部分进行的。
我的训练X的形状为(6681, 96, 4),训练Y的形状为(6681, 48),因为我只限制了一个传感器。如果我在训练时将训练Y更改为(6681, 48, 4),当然会遇到
我卡住的地方在于LSTM层的输入/输出形状。 我就是无法弄清楚如何最终得到一个形状为(BATCH_SIZE,48, 4)的形状。
这是我目前的层设置:
![enter image description here](https://istack.dev59.com/ipXrf.webp)
到目前为止,我已经实现了一种只能预测一个传感器的方法,并且大多数是按照TensorFlow教程中的这一部分进行的。
我的训练X的形状为(6681, 96, 4),训练Y的形状为(6681, 48),因为我只限制了一个传感器。如果我在训练时将训练Y更改为(6681, 48, 4),当然会遇到
ValueError: Dimensions must be equal, but are 48 and 4 for 'loss/dense_loss/sub' (op: 'Sub') with input shapes: [?,48], [?,48,4].
的错误,因为我的模型不期望此形状。我卡住的地方在于LSTM层的输入/输出形状。 我就是无法弄清楚如何最终得到一个形状为(BATCH_SIZE,48, 4)的形状。
这是我目前的层设置:
tf.keras.backend.clear_session()
print("Input shape", x_train_multi.shape[-2:])
multi_step_model = tf.keras.models.Sequential()
multi_step_model.add(tf.keras.layers.LSTM(32,
return_sequences=True,
input_shape=x_train_multi.shape[-2:]))
multi_step_model.add(tf.keras.layers.Dropout(rate=0.5)) # Dropout layer after each LSTM to reduce overfitting.
multi_step_model.add(tf.keras.layers.LSTM(16, activation='relu'))
multi_step_model.add(tf.keras.layers.Dropout(rate=0.5))
# The argument to Dense shapes the results to give the number of time steps we want.
# But how do I make it keep 4 features as well?!?
multi_step_model.add(tf.keras.layers.Dense(future_target / STEP))
multi_step_model.compile(optimizer=tf.keras.optimizers.RMSprop(clipvalue=1.0), loss='mae')
# Shape of predictions
for x, y in val_data_multi.take(1):
print ("Prediction shape", multi_step_model.predict(x).shape)
一些想法:
- 我是不是漏掉了什么或者忘记设置输出特征/维度的参数?
- 我需要为预测每个传感器训练单独的RNN吗?
谢谢! :)
Dropout
层。它们有自己的recurrent_dropout
参数。总体而言,RNN与dropout不兼容。 - David Arenburg