Models: The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph.

Created on 28 Apr 2018  路  15Comments  路  Source: tensorflow/models

If I use the model of ssd_mobilenet_v1_coco_2017_11_17,when I run " image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0') ",it works.

If I use other modle ,such as " ssd_inception_v2_coco_2017_11_17 ",when I run "image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')",it errors.

Traceback (most recent call last):
File "F:/project/demo/demo1.py", line 103, in
output_dict = run_inference_for_single_image(image_array, detection_graph)
File "F:/project/demo/demo1.py", line 89, in run_inference_for_single_image
image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')
File "F:\project\demo\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 3207, in get_tensor_by_name
return self.as_graph_element(name, allow_tensor=True, allow_operation=False)
File "F:\project\demo\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 3035, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "F:\project\demo\venv\lib\site-packages\tensorflow\python\framework\ops.py", line 3077, in _as_graph_element_locked
"graph." % (repr(name), repr(op_name)))
KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."
If anyone used other model' s frozen_inference_graph.pb ,please give demo code or advices ,thanks!

awaiting response

Most helpful comment

replace the following line:
image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')
by:
image_tensor = 'image_tensor:0'

Repeat the same for all the other "get_tensor_by_name" lines of code
We need not find the tensors in the graph.

Working code:

image_tensor = 'image_tensor:0'
boxes = 'detection_boxes:0'
scores = 'detection_scores:0'
classes = 'detection_classes:0'
num_detections = 'num_detections:0'

output_dict = sess.run([boxes, scores, classes, num_detections],
                feed_dict={image_tensor: image_arrays})

Note: image_arrays is the input image (with expanded_dims)

All 15 comments

Thank you for your post. We noticed you have not filled out the following field in the issue template. Could you update them if they are relevant in your case, or leave them as N/A? Thanks.
What is the top-level directory of the model you are using
Have I written custom code
OS Platform and Distribution
TensorFlow installed from
TensorFlow version
Bazel version
CUDA/cuDNN version
GPU model and memory
Exact command to reproduce

I have solved the question just by upgrading the version of tensorflow from 1.4 to 1.6.
thanks

I have tensorflow version 1.8 and I am facing the same issue.

KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."
SSD_Moblenet_V1 works fine but this error arises with SSD_Mobilenet_V2. I have no idea what is the problem.

Any help would be appreciated. Thanks

Have the same issue with faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28

image_tensor:0 should refer input node name in ur graph.

same issue on tensorflow 1.11

I have the same issue

@MR-520DAI... Did you able to solve it

if you still cant solve it, try use another version of python.
try python 3.5.
there are some library not compatible in python 3.7

Any solutions ?
Facing the same problem.

replace the following line:
image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')
by:
image_tensor = 'image_tensor:0'

Repeat the same for all the other "get_tensor_by_name" lines of code
We need not find the tensors in the graph.

Working code:

image_tensor = 'image_tensor:0'
boxes = 'detection_boxes:0'
scores = 'detection_scores:0'
classes = 'detection_classes:0'
num_detections = 'num_detections:0'

output_dict = sess.run([boxes, scores, classes, num_detections],
                feed_dict={image_tensor: image_arrays})

Note: image_arrays is the input image (with expanded_dims)

Hi All, I'm training custom data set in TF2 and now i have finished training the model. To test my model with the test image what should i do??

I tried to follow the same steps as in Tensorflow1 but i couldn't get the desired output. Also, i'm not able to generate the .pb to run the object detection script.

Any suggestions or help would be highly recommended. thanks in advance. below is the screenshot of the error that i get when i run the object detection script from TF1 version.

Capture

replace the following line:
image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')
by:
image_tensor = 'image_tensor:0'

Repeat the same for all the other "get_tensor_by_name" lines of code
We need not find the tensors in the graph.

Working code:

image_tensor = 'image_tensor:0'
boxes = 'detection_boxes:0'
scores = 'detection_scores:0'
classes = 'detection_classes:0'
num_detections = 'num_detections:0'

output_dict = sess.run([boxes, scores, classes, num_detections],
                feed_dict={image_tensor: image_arrays})

Note: image_arrays is the input image (with expanded_dims)

Hi All, I'm training custom data set in TF2 and now i have finished training the model. To test my model with the test image what should i do??

I tried to follow the same steps as in Tensorflow1 but i couldn't get the desired output. Also, i'm not able to generate the .pb to run the object detection script.

Any suggestions or help would be highly recommended. thanks in advance. below is the screenshot of the error that i get when i run the object detection script from TF1 version.

I tried both methods and none worked:

image_tensor = 'image_tensor:0'
boxes, scores, classes, _  = sess.run([boxes, scores, classes, num_detections],
                       feed_dict={image_tensor: np.expand_dims(img, 0)})

Throws error:
TypeError: Cannot interpret feed_dict key as Tensor: The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph.

And

image_tensor = tf.get_default_graph().get_tensor_by_name('image_tensor:0')
boxes, scores, classes, _  = sess.run([boxes, scores, classes, num_detections],
                       feed_dict={image_tensor: np.expand_dims(img, 0)})

Throws:
KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."

Exported my TensorFlow model from Custom Vision AI.

image

The predict Python script that is included with the model is broken. Making this problematic for anyone trying to use their models downloaded from Microsoft Custom Vision AI.

image

It seems that I am experiencing the same problem that everyone else is.

image

Traceback (most recent call last): File "c:\Users\Tyler\Desktop\TensorFlow\python\predict.py", line 64, in <module> main() File "c:\Users\Tyler\Desktop\TensorFlow\python\predict.py", line 55, in main predictions = predict(args.model_filename, args.image_filename) File "c:\Users\Tyler\Desktop\TensorFlow\python\predict.py", line 42, in predict od_model = ObjectDetection(model_filename) File "c:\Users\Tyler\Desktop\TensorFlow\python\predict.py", line 28, in __init__ self.input_shape = sess.graph.get_tensor_by_name(self.INPUT_TENSOR_NAME).shape.as_list()[1:3] File "C:\Users\Tyler\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 3846, in get_tensor_by_name return self.as_graph_element(name, allow_tensor=True, allow_operation=False) File "C:\Users\Tyler\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 3670, in as_graph_element return self._as_graph_element_locked(obj, allow_tensor, allow_operation) File "C:\Users\Tyler\AppData\Local\Programs\Python\Python38\lib\site-packages\tensorflow\python\framework\ops.py", line 3710, in _as_graph_element_locked raise KeyError("The name %s refers to a Tensor which does not " KeyError: "The name 'image_tensor:0' refers to a Tensor which does not exist. The operation, 'image_tensor', does not exist in the graph."

Was this page helpful?
0 / 5 - 0 ratings