【问题标题】:TensorFlow: The tensor is not the element of this graphTensorFlow:张量不是该图的元素
【发布时间】:2017-05-27 16:18:28
【问题描述】:
#file for inputing the data for testing
from scipy import ndimage
image_file='test.png'
image_data = ndimage.imread(image_file).astype(float) 
image_data = image_data.reshape((-1, image_size * image_size)).astype(np.float32)
rst = tf.Graph()
with rst.as_default():
     result = tf.matmul(image_data, weights) + biases
     picko=tf.nn.softmax(result)
with tf.Session(graph=rst) as rsts:
     tf.global_variables_initializer().run()
     predictions = rsts.run([picko])

运行上述代码时出现以下错误。请建议我一个我无法手动解决的解决方案。

ValueError: Fetch 参数不能解释为张量。 (Tensor Tensor("Softmax_4:0", shape=(1, 10), dtype=float32) 不是这个图的元素。)

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    试试这个代码。

    主要区别在于整个代码使用默认图,没有一个使用创建的图。

    #file for inputing the data for testing
    from scipy import ndimage
    image_file = 'test.png'
    image_data = ndimage.imread(image_file).astype(float) 
    image_data = image_data.reshape((-1, image_size * image_size)).astype(np.float32)    
    result = tf.matmul(image_data, weights) + biases
    picko = tf.nn.softmax(result)
    with tf.Session() as rsts:
         tf.global_variables_initializer().run()
         predictions = rsts.run([picko])
    

    【讨论】:

    • 您的代码可能有问题的原因是您将 rst 作为默认范围,但您在其之外定义了其他张量,基本上混合了您放置张量的位置。
    • 我将图形作为参数传递给会话,那有什么用?
    • 另一种方法是定义一个图并在其中定义所有张量,包括 image_data 、 weights 和 bias
    • 这能解决您的错误信息吗?如果是这样,请接受这个作为正确答案。我很乐意在另一个问题中研究其他架构
    猜你喜欢
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多