How to export frozen_inference_graph.pb from a checkpoint in Tensorflow Objectdetection 2

Viewed 4297

how can I export a trained model to frozen_inference_graph.pb instead of saved_model.pb, because when I use the exporter_main_v2.py that comes with Tensorflow object detection v2 it gives me a folder

├─ exported-models/
   └─ my_model/ 
      ├─ checkpoint/
      ├─ saved_model/
            └─ assets/
            ├─ variables/
            └─ saved_model.pb
      └─ pipeline.config

and inside the save_model I have saved_model.pb but the issue is that I can't use it alone for inference but I need to use the variable folder that comes with it. that't why I'm asking if theire is a way to export a trained model to frozen_inference_graph.pb to use it for inference without need for variables folderlike in TF1.

2 Answers

Unfortunately, TF2 does not support the export_inference_graph.py, which would do the exact thing you've asked for - but only for TF1. The exporter_main_v2.py won't export any frozen graph.

What you can do is freeze your graph using

from tensorflow.python.tools import freeze_graph
freeze_graph.freeze_graph(...)

You can also find the file freeze_graph.py on your computer in tensorflow\python\tools, which is quite well commented on how to use it. Also, you can have a look at this how to freeze it: freeze_graph_test However, TF2 is not intended to produce frozen graphs any more!

EDIT: Nice workaround can be found here

Related