Converting your inference graph file to a Tensorflow lite (.tflite) file

This is an important aspect to convert the large-sized model file to a lighter one. This lighter model can be deployed on mobile phones, wearables, and Raspberry Pi.

We will start by creating a TensorFlow frozen graph with compatible ops that can be used with TensorFlow lite. This is done by running the command below from the object_detection folder

Run the below mentioned python command from the folder


python object_detection/ \ — input_type image_tensor \ — pipeline_config_path object_detection/testing_models/pipeline.config \ — trained_checkpoint_prefix object_detection/testing_models/ripper/model.ckpt-17463 \ — output_directory object_detection/testing_models/tflite/ — add_postprocessing_op=true

This will create a directory named tflite that contains two folders — tflite_graph.pb and tflite_graph.pbtxt

Now we will convert the frozen graph (.pb file) into a tflite (.tflite) file

Run the below mentioned python command from the folder


tflite_convert — graph_def_file=/Users/sivakumarswaminathan/anaconda3/lib/python3.7/site-packages/tensorflow/models/research/object_detection/testing_models/tflite/tflite_graph.pb — output_file=/Users/sivakumarswaminathan/anaconda3/lib/python3.7/site-packages/tensorflow/models/research/object_detection/testing_models/tflite/detect.tflite/detect.tflite — output_format=TFLITE — input_shapes=1,300,300,3 — input_arrays=normalized_input_image_tensor — output_arrays=’TFLite_Detection_PostProcess’,’TFLite_Detection_PostProcess:1',’TFLite_Detection_PostProcess:2',’TFLite_Detection_PostProcess:3' — inference_type=QUANTIZED_UINT8 — mean_values=128 — std_dev_values=127 — change_concat_input_ranges=false — allow_custom_ops — default_ranges_min=0 — default_ranges_max=255

Here, we would be able to generate a .tflite file whose file size is generally not more than 5MB. The file size has to be strictly verified that it never crosses 5 MB so that these files could be deployed on the lighter devices

Thank you for your time and attention, and I would certainly love to have your appreciations in form of 👏 !

Senior Android Developer | AR Developer @ a popular Automotive Company | Prev. Android Application Developer @tinysurprise | IIM Trichy Alumini