TensorFlow:张量不是该图的元素

2024-04-24

#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:获取参数不能解释为张量。 (Tensor Tensor("Softmax_4:0", shape=(1, 10), dtype=float32) 不是该图的元素。)


试试这个代码。

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

#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])
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TensorFlow:张量不是该图的元素 的相关文章

随机推荐