【问题标题】:TypeError('The value of a feed cannot be a tf.Tensor object....) though I am providing it a numpy arrayTypeError('The value of a feed cannot be a tf.Tensor object....) 尽管我提供了一个 numpy 数组
【发布时间】:2017-11-16 08:44:00
【问题描述】:

我正在向我的 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
            })

这是 tensorflow 库中的错误吗,因为我想将其作为问题发布但不确定。非常感谢任何帮助。 谢谢

【问题讨论】:

    标签: python-2.7 numpy multidimensional-array tensorflow


    【解决方案1】:

    我认为您的问题不在于 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 之前打印它们中的每一个以找出哪个是张量

    【讨论】:

    • 谢谢萨尔瓦多。我发现我的错误。这是另一个张量变量。
    猜你喜欢
    • 2023-04-10
    • 2022-12-01
    • 2020-10-19
    • 2021-10-15
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多