tensorflow / models

Models and examples built with TensorFlow
Other
77.25k stars 45.75k forks source link

od_graph_def.ParseFromString(serialized_graph) error while running inference in object_detection #8974

Open shamik111691 opened 4 years ago

shamik111691 commented 4 years ago

Prerequisites

Please answer the following questions for yourself before submitting an issue.

1. The entire URL of the file you are using

https://github.com/tensorflow/models/tree/master/research/...

2. Describe the bug

Inference fails when trying to read graph Trying saved_model/saved_model.pb

frozen_inference_graph.pb was not produced by exporter_main_v2.py

3. Steps to reproduce

detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.compat.v1.GraphDef() with tf.compat.v2.io.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='')

4. Expected behavior

Inference should not fail

5. Additional context

Include any logs that would be helpful to diagnose the problem.

6. System information

ravikyram commented 4 years ago

@shamik111691

What is the top-level directory of the model you are using? Please, let us know which pretrained model you are using and share related code .Thanks!

shamik111691 commented 4 years ago

@ravikyram

I am using object_detection.

I am using the faster_rcnn_inception_resnet_v2_keras. I am training my own model from scratch.

Related code for inference: PATH_TO_CKPT = /saved_model/saved_model.pb detection_graph = tf.Graph() with detection_graph.as_default(): od_graph_def = tf.compat.v1.GraphDef() with tf.compat.v2.io.gfile.GFile(PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='')

nicholasguimaraes commented 4 years ago

I'm having the same issue

shamik111691 commented 4 years ago

@nicholasguimaraes I was able to solve this. You have to read in the saved_model. Please look at the colab_tutorials/object_detection_tutorial.ipynb

nicholasguimaraes commented 4 years ago

@shamik111691 I'm reading it from the saved_model folder. After converting the model it did not create any inference_graph.pb only saved_model.pb under saved_model folder.

Thank you I'm going to take a look at the link

gunarms commented 4 years ago

@nicholasguimaraes what ended up being the solution to this?

shreyanshu09 commented 3 years ago

@shamik111691 I am also stuck in the same problem. Can you please help me where I can change it?

This is the part of my code

MODEL_NAME='faster_rcnn_inception_v2_coco_2018_01_28' self.PATH_TO_CKPT = os.path.join(self.CWD_PATH, 'models', 'research', 'object_detection', self.MODEL_NAME,'frozen_inference_graph.pb') self.detection_graph = tf.Graph() with self.detection_graph.as_default(): od_graph_def = tf.compat.v1.GraphDef() with tf.compat.v2.io.gfile.GFile(self.PATH_TO_CKPT, 'rb') as fid: serialized_graph = fid.read() od_graph_def.ParseFromString(serialized_graph) tf.import_graph_def(od_graph_def, name='')

saniasinghanicourse1 commented 1 year ago

Hi, did anyone find a solution?