TensorFlow:张量不是这个图的元素 [英] TensorFlow: The tensor is not the element of this graph
本文介绍了TensorFlow:张量不是这个图的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#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])
运行上述代码时出现以下错误.请给我建议一个我无法手动解决的解决方案.
When running the above code I am getting the below error .Please suggest me a solution I am not able to solve it manually .
ValueError: Fetch 参数不能解释为张量.(Tensor Tensor("Softmax_4:0", shape=(1, 10), dtype=float32) 不是这个图的元素.)
ValueError: Fetch argument cannot be interpreted as a Tensor. (Tensor Tensor("Softmax_4:0", shape=(1, 10), dtype=float32) is not an element of this graph.)
推荐答案
试试这个代码.
主要区别在于整个代码使用默认图形,没有使用创建的图形.
The main difference is that the whole code uses the default graph and none of it uses a created graph.
#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])
这篇关于TensorFlow:张量不是这个图的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文