models icon indicating copy to clipboard operation
models copied to clipboard

How to convert SSD Inception V2 to TFlite?

Open mrtpk123 opened this issue 5 years ago • 3 comments

Prerequisites

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

  • [ ] Using TF2
  • [ ] I want to convert SSD Inception V2 to TFlite

1. The entire URL of the file you are using

http://download.tensorflow.org/models/object_detection/ssd_inception_v2_coco_2018_01_28.tar.gz

2. Describe the bug

Tried to convert the frozen graph to TFlite using python3 object_detection/export_tflite_graph_tf2.py and understood that this specific model is not supported yet. Then tried to convert the model using object_detection/export_tflite_ssd_graph.py. But failed with an error RuntimeError: tf.placeholder() is not compatible with eager execution.. Tried disabling "eager execution" by calling tf.compat.v1.disable_eager_execution().

Is there any way to get tflite model file of "SSD Inception V2". Any pointers/help is hugely appreciated.

mrtpk123 avatar Mar 12 '21 10:03 mrtpk123

Hi @mrtpk123

Since you are using a model from TF1 Object Detection Zoo if you untar the file you will see a frozen_inference_graph.pb

We can use that file to generate a tflite model using TFLiteConverter.

For Tensorflow 2:

import​ ​tensorflow​ ​as​ ​tf​

​# Convert the model.​
​converter​ ​=​ ​tf​.​compat​.​v1​.​lite​.​TFLiteConverter​.​from_frozen_graph​(
    ​graph_def_file​, ​input_arrays, input_shapes​, ​output_arrays​
) 
​tflite_model​ ​=​ ​converter​.​convert​()

​# Save the model.​
​with​ ​open​(​'model.tflite'​, ​wb'​) ​as​ ​f​:
  ​f​.​write​(​tflite_model​)

Click Here to visit the official documentation

Nkosana-263 avatar Mar 12 '21 14:03 Nkosana-263

Thank you @Nkosana-263; I have been stuck at this for a few days and your solution helped me. Thank you a lot.

mrtpk123 avatar Mar 12 '21 14:03 mrtpk123

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Mar 12 '21 14:03 google-ml-butler[bot]