Kanwarkajla
Kanwarkajla

Reputation: 51

TensorFlow: The tensor is not the element of this 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)
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 argument cannot be interpreted as a Tensor. (Tensor Tensor("Softmax_4:0", shape=(1, 10), dtype=float32) is not an element of this graph.)

Upvotes: 2

Views: 3967

Answers (1)

Anton Panchishin
Anton Panchishin

Reputation: 3763

Try this code.

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])

Upvotes: 0

Related Questions