Intel® Distribution of OpenVINO™ Toolkit
Community support and discussions about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all things computer vision-related on Intel® platforms.
5765 Discussions

Error converting TF-OD-API model to IR format with Model Optimizer

Michael_Popikov
Beginner
505 Views

I have a trained from sketch ssd-mobile-net-v1_640x640 from tensorflow model garden. It correctly inferences on tf, but when I`m trying to freeze the graph and pass it to model optimizer I`m getting the following bug report.


What may be the reason and how am I able to fix that stuff? I`ll provide any additional information required.

 


[ ERROR ] -------------------------------------------------
[ ERROR ] ----------------- INTERNAL ERROR ----------------
[ ERROR ] Unexpected exception happened.
[ ERROR ] Please contact Model Optimizer developers and forward the following information:
[ ERROR ] Exception occurred during running replacer "ObjectDetectionAPIPreprocessor2Replacement (<class 'extensions.front.tf.ObjectDetectionAPI.ObjectDetectionAPIPreprocessor2Replacement'>)": 
[ ERROR ] Traceback (most recent call last):
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/utils/class_registration.py", line 290, in apply_transform
for_graph_and_each_sub_graph_recursively(graph, replacer.find_and_replace_pattern)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/middle/pattern_match.py", line 59, in for_graph_and_each_sub_graph_recursively
func(graph)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/front/tf/replacement.py", line 48, in find_and_replace_pattern
self.transform_graph(graph, desc._replacement_desc['custom_attributes'])Fi "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/extensions/front/tf/ObjectDetectionAPI.py", line 604, in transform_graph
assert start_nodes[0] in graph.nodes
AssertionError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/main.py", line 345, in main
ret_code = driver(argv)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/main.py", line 309, in driver
ret_res = emit_ir(prepare_ir(argv), argv)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/main.py", line 252, in prepare_ir graph = unified_pipeline(argv)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/pipeline/unified.py", line 25, in unified_pipeline
class_registration.apply_replacements(graph, [
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/utils/class_registration.py", line 340, in apply_replacements
apply_replacements_list(graph, replacers_order)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/utils/class_registration.py", line 326, in apply_replacements_list
apply_transform(
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/utils/logger.py", line 124, in wrapper
function(*args, **kwargs)
File "/opt/intel/openvino_2021.3.394/deployment_tools/model_optimizer/mo/utils/class_registration.py", line 314, in apply_transform
raise Exception('Exception occurred during running replacer "{} ({})": {}'.format(
Exception: Exception occurred during running replacer "ObjectDetectionAPIPreprocessor2Replacement (<class 'extensions.front.tf.ObjectDetectionAPI.ObjectDetectionAPIPreprocessor2Replacement'>)": 

[ ERROR ] ---------------- END OF BUG REPORT --------------
[ ERROR ] -------------------------------------------------

0 Kudos
6 Replies
Syamimi_Intel
Moderator
461 Views

Hi Михаил Попиков,

Thank you for reaching out. I have tried to find this model in Tensorflow Model Garden but I couldn't find it.

Can you share the model with us ?

 

On another note, SSD MobileNet V1 FPN COCO   (ssd_mobilenet_v1_fpn_shared_box_predictor_640x640_coco14_sync_2018_07_03) model from TensorFlow 1 Detection Model Zoo is supported by OpenVINO.  I used the following command to convert the model: 

 

python mo.py --reverse_input_channels --input_shape=[1,640,640,3] --input=image_tensor --output=detection_scores,detection_boxes,num_detections --transformations_config="C:\Program Files (x86)\Intel\openvino_2021.3.394\deployment_tools\model_optimizer\extensions\front\tf\ssd_v2_support.json" --tensorflow_object_detection_api_pipeline_config="C:\Program Files (x86)\Intel\openvino_2021.3.394\ssd_mobilenet_v1_fpn\pipeline.config" --input_model="C:\Program Files (x86)\Intel\openvino_2021.3.394\ssd_mobilenet_v1_fpn\frozen_inference_graph.pb"

 

These arguments are also available at:

https://github.com/openvinotoolkit/open_model_zoo/blob/2021.3/models/public/ssd_mobilenet_v1_fpn_coc...

 

 

OpenVINO also supports SSD MobileNet V1 FPN 640x640 from TensorFlow 2 Detection Model Zoo as well.  I used the following command to convert this model: 

 

python mo_tf.py --saved_model_dir "C:\Program Files (x86)\Intel\openvino_2021.3.394\ssd_mobilenet_v1\saved_model" --transformations_config="C:\Program Files (x86)\Intel\openvino_2021.3.394\deployment_tools\model_optimizer\extensions\front\tf\ssd_support_api_v2.0.json" --tensorflow_object_detection_api_pipeline_config="C:\Program Files (x86)\Intel\openvino_2021.3.394\ssd_mobilenet_v1\pipeline.config"

 

Regards,

Syamimi

Michael_Popikov
Beginner
439 Views

Thanks a lot! I`ll try your method out and post results here. Seems like mentioned model`s name in a bit incorrect way) That was  SSD MobileNet V1 FPN 640x640 from TensorFlow 2 Detection Model Zoo.

The only question I have is how you get saved model? Are you just using exporter_main_v2 from from research/object_detection?

 

Syamimi_Intel
Moderator
408 Views

Hi Михаил Попиков,

The saved_model folder is available in ssd_mobilenet_v1_fpn_640x640_coco17_tpu-8.tar.gz folder. You can download this folder using the following steps:

  1. Right click on the Model name (SSD MobileNet V1 FPN 640x640) in TensorFlow 2 Detection Model Zoo.
  2. Click on Copy link address to copy the download link of the model.
  3. Paste the link in a new browser tab and press enter to download the model.

 


Regards,

Syamimi

 


Michael_Popikov
Beginner
391 Views

That`s what I was actually doing, I mean how do export this model after you train it to get correct format for optimization? We do have just checkpoint when we train it from sketch, so we have to export it using exporter_main, but I`m stuck on  optimizing stage after this 

 

Syamimi_Intel
Moderator
352 Views

Hi Михаил Попиков,

You can have a try with using the latest master branch as it includes the PR Enable TF 2.0 Object Detection API models #3556 or you can wait until OpenVINO 2021.4 Intel Distribution package. Also, you can refer to Converting a TensorFlow* Model as this page includes various conversion techniques for frozen models as well as for non-frozen/checkpoint. 



Regards,

Syamimi


Syamimi_Intel
Moderator
289 Views

Hi Михаил Попиков,

This thread will no longer be monitored since we have provided a solution. If you need any additional information from Intel, please submit a new question.



Regards,

Syamimi


Reply