TypeError(' feed的值不能是tf.Tensor对象....)虽然我提供了一个numpy数组

时间:2017-06-14 09:25:17

标签: python-2.7 numpy multidimensional-array tensorflow

我向feed_dict提供了一个numpy数组,但它仍然给出了这个错误,即feed需要是一个tf.Tensor对象。

index = tf.placeholder(tf.int32, shape=[None], name='index')
dontknow = np.random.choice(range(1,200), 180)
_, summary = sess.run([train, merged], feed_dict={
            input_placeholder:train_batch_x,
            attr_placeholder:train_class_attr,
            label_placeholder:train_batch_y,
            index:dontknow
            })

这是张量流库中的一个错误,因为我想发布一个问题,但不确定。任何帮助都非常感谢。 感谢

1 个答案:

答案 0 :(得分:0)

我认为您的问题不在于dontknow变量,而在于其中一个:

input_placeholder:train_batch_x,
attr_placeholder:train_class_attr,
label_placeholder:train_batch_y,  

当我删除它们时,我可以毫无错误地执行你的东西:

import tensorflow as tf
import numpy as np

index = tf.placeholder(tf.int32, shape=[None], name='index')
dontknow = np.random.choice(range(1,200), 180)

with tf.Session() as sess:
    print sess.run(index, {index:dontknow})

在执行sess.run之前打印每一个,以找出哪个是张量