我是tensorflow的新手,我想进行一些时间序列预测并遵循this链接。我想将36小时的数据作为输入,并将下一个连续的48小时的数据作为输出数据,因此我按如下所示进行了x和y批处理:
""" Making our training dataset with batch size of num_period """
x_batches = {'NSW': X_NSW.transpose().reshape(-1,72,1),
'QLD': X_QLD.transpose().reshape(-1,72,1),
'SA': X_SA.transpose().reshape(-1,72,1),
'TAS': X_TAS.transpose().reshape(-1,72,1),
'VIC': X_VIC.transpose().reshape(-1,72,1)}
y_batches = {'NSW': Y_NSW.transpose().reshape(-1,96,1),
'QLD': Y_QLD.transpose().reshape(-1,96,1),
'SA': Y_SA.transpose().reshape(-1,96,1),
'TAS': Y_TAS.transpose().reshape(-1,96,1),
'VIC': Y_VIC.transpose().reshape(-1,96,1)}
然后我使用上面链接中给出的相同代码(但根据需要对其进行了修改),并获得了以下代码:
inputs = 1 #input vector size
hidden = 100
output = 1 #output vector size
X = tf.placeholder(tf.float32, [None, 72, inputs])
y = tf.placeholder(tf.float32, [None, 96, output])
basic_cell = tf.contrib.rnn.BasicRNNCell(num_units=hidden, activation=tf.nn.relu)
rnn_output, states = tf.nn.dynamic_rnn(basic_cell, X, dtype=tf.float32)
learning_rate = 0.001 #small learning rate so we don't overshoot the minimum
stacked_rnn_output = tf.reshape(rnn_output, [-1, hidden]) #change the form into a tensor
stacked_outputs = tf.layers.dense(stacked_rnn_output, output) #specify the type of layer (dense)
outputs = tf.reshape(stacked_outputs, [-1, 96, output]) #shape of results
但是系统抛出以下错误
outputs = tf.reshape(stacked_outputs, [-1, 96, output]) #shape of results
...
InvalidArgumentError (see above for traceback): Input to reshape is a tensor with 4104 values, but the requested shape requires a multiple of 96
[[Node: Reshape_1 = Reshape[T=DT_FLOAT, Tshape=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](dense/BiasAdd, Reshape_1/shape)]]
我知道我在下一行中犯了一些错误,但我无法弄清楚。
stacked_rnn_output = tf.reshape(rnn_output, [-1, hidden]) #change the form into a tensor
stacked_outputs = tf.layers.dense(stacked_rnn_output, output) #specify the type of layer (dense)
outputs = tf.reshape(stacked_outputs, [-1, 96, output]) #shape of results
答案 0 :(得分:0)
问题与您如何设置任务有关。 RNN为任何单个输入输出一个值:如果输入序列的长度为72步长,那么您的输出序列的长度将为72步长,因此您无需要求重塑为96步长的序列。
两种解决方案(但显然取决于您当前要求算法学习的内容):