【发布时间】:2018-07-19 16:17:39
【问题描述】:
我是 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
【问题讨论】:
标签: python tensorflow