ValueError:无法为张量为'(?,1)'的张量'Placeholder_1:0'输入形状(6165,5)的值

时间:2019-12-02 15:13:46

标签: tensorflow time-series artificial-intelligence prediction recurrent-neural-network

--volumes

我遇到了一个错误,我只是检查了每个变量的维数,它看起来一样,没有任何问题...您能告诉我什么是错误的以及如何解决吗?

我想做的是天气预报。 输入形状将为(xxxx,5),这里xxxx是输入数据中的行数,而5是输入类型,包括平均温度,等等。

输出形状必须为(yyyy,1),仅因为其列将具有预测的降水量。

奇怪的是,当程序正在读取文件时,Data_Y的形状为(hhhh,5),应该是(yyyy,1)。

我认为这是造成这里所有错误的原因。

输入文件的链接如下

Input file

enter image description here

如何解决此问题?请给我你的帮助。

> WARNING: The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
  * https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
  * https://github.com/tensorflow/addons
If you depend on functionality not listed there, please file an issue.

WARNING:tensorflow:From C:/Users/SONSANGWOO/Desktop/Euroaquae/The_third_semester_at_BCN/ANN/Exercise/TimeSeriespy_RNN.py:74: BasicLSTMCell.__init__ (from tensorflow.python.ops.rnn_cell_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This class is equivalent as tf.keras.layers.LSTMCell, and will be replaced by that in Tensorflow 2.0.
WARNING:tensorflow:From C:/Users/SONSANGWOO/Desktop/Euroaquae/The_third_semester_at_BCN/ANN/Exercise/TimeSeriespy_RNN.py:75: dynamic_rnn (from tensorflow.python.ops.rnn) is deprecated and will be removed in a future version.
Instructions for updating:
Please use `keras.layers.RNN(cell)`, which is equivalent to this API
WARNING:tensorflow:From C:\Users\SONSANGWOO\Anaconda3\lib\site-packages\tensorflow\python\ops\tensor_array_ops.py:162: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
Traceback (most recent call last):

  File "<ipython-input-1-7716630f4e29>", line 1, in <module>
    runfile('C:/Users/SONSANGWOO/Desktop/Euroaquae/The_third_semester_at_BCN/ANN/Exercise/TimeSeriespy_RNN.py', wdir='C:/Users/SONSANGWOO/Desktop/Euroaquae/The_third_semester_at_BCN/ANN/Exercise')

  File "C:\Users\SONSANGWOO\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 704, in runfile
    execfile(filename, namespace)

  File "C:\Users\SONSANGWOO\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 108, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/SONSANGWOO/Desktop/Euroaquae/The_third_semester_at_BCN/ANN/Exercise/TimeSeriespy_RNN.py", line 97, in <module>
    X: trainX, Y: trainY})

  File "C:\Users\SONSANGWOO\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 929, in run
    run_metadata_ptr)

  File "C:\Users\SONSANGWOO\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1128, in _run
    str(subfeed_t.get_shape())))

ValueError: Cannot feed value of shape (6165, 5) for Tensor 'Placeholder_1:0', which has shape '(?, 1)'

1 个答案:

答案 0 :(得分:0)

鉴于您提供的信息,这是一个解决方案。很显然,您可能已经意识到,问题出在build_dataset函数中。您需要将功能更改为以下内容。

def build_dataset(data, seq_length):
  dataX = []
  dataY = []
  for i in range(seq_length):
    dataX.append(data[i:data.shape[0]-(seq_length-i)].reshape(-1, 1, 5))
  dataX = np.concatenate(dataX, axis=1)
  dataY = data[i+1:train_set.shape[0],4].reshape(-1, 1)
  return dataX, dataY

此函数以以下方式返回数据。假设您有以下几行,

22.90 20.20 31.00 93.00 0.00
22.90 21.20 26.00 91.00 0.00
22.40 20.20 27.40 89.00 0.00
22.40 15.40 29.00 90.00 0.00
21.30 14.40 26.00 82.00 0.00
21.50 20.20 23.00 96.00 0.00
22.10 17.20 23.60 97.00 20.70

它为X提供

22.90 20.20 31.00 93.00 0.00
22.90 21.20 26.00 91.00 0.00
22.40 20.20 27.40 89.00 0.00
22.40 15.40 29.00 90.00 0.00
21.30 14.40 26.00 82.00 0.00
21.50 20.20 23.00 96.00 0.00

输出Y20.70

对于完整的数据集,结果为以下形状。

Input: (6165, 6, 5)
Output: (6165, 1)