Tensorflow feed_dict with tensorflow.python.framework.errors.InvalidArgumentError

时间:2016-07-09 15:12:55

标签: python-2.7 tensorflow deep-learning

我的例子如下:

import tensorflow as tf
import numpy as np


batch_size = 10
real_data = np.ndarray(shape=(batch_size, 1), dtype=np.int32)
for i in range(batch_size):
    real_data[i] = i
print np.shape(real_data)

holder = tf.placeholder(tf.int32, shape=[None, 1])

with tf.Session() as sess:
    feed_dict = {
        holder: real_data
    }
    sess.run([], feed_dict=feed_dict)

输出结果如下:

/home/att/anaconda2/bin/python /home/att/文档/code/justtest/ates.py
(10, 1)
Traceback (most recent call last):
  File "/home/att/文档/code/justtest/ates.py", line 17, in <module>
    sess.run([], feed_dict=feed_dict)
  File "/home/att/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/ session.py", line 340, in run
    run_metadata_ptr)
  File "/home/att/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/ session.py", line 564, in _run
    feed_dict_string, options, run_metadata)
  File "/home/att/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/ session.py", line 637, in _do_run
    target_list, options, run_metadata)
  File "/home/att/anaconda2/lib/python2.7/site-packages/tensorflow/python/client/ session.py", line 659, in _do_call
    e.code)
tensorflow.python.framework.errors.InvalidArgumentError

Process finished with exit code 1

令我困惑的是数据形状与占位符完全相同,两者都是(10,1),但为什么还会引发此错误?另一个问题是,当我将数据提供给占位符时,数据应该是什么样的(数据类型和数据形状)?

任何帮助将不胜感激:)

1 个答案:

答案 0 :(得分:0)

您无法使用sess.run([]),您需要在内部提供图形节点,如:

sess.run([some_node], feed_dict=feed_dict)