I use ssd_mobilenets in Object detection API to train my own model, and get .ckpt files. It works well on my computer, but now I want to use the model on my phone. So, I need convert it to .pb file. I do not know how to do it, can any one help? By the way, the graph of ssd_mobilenets is complex, I can not find which is the output of model. Is there any one knowing the name of the output?
            Asked
            
        
        
            Active
            
        
            Viewed 9,094 times
        
    2 Answers
2
            
            
        Use export_inference_graph.py to convert model checkpoint file into a .pb file.
python tensorflow_models/object_detection/export_inference_graph.py \
--input_type image_tensor \
--pipeline_config_path architecture_used_while_training.config \
--trained path_to_saved_ckpt/model.ckpt-NUMBER \
--output_directory model/
        Salman Ghauri
        
- 574
 - 1
 - 5
 - 16
 
- 
                    I created a `.ckpt` file using `tf.train.Saver()`, but it didn't give me a `.config` file. Where does that come from? – jss367 Aug 14 '19 at 14:55
 - 
                    Use the same config file that you used to train the model or take one from sample configs given by TF – Salman Ghauri Aug 15 '19 at 07:52
 
0
            
            
        This is the 4th code cell in object_detection_tutorial.ipynb in this link -https://github.com/tensorflow/models/blob/master/research/object_detection/object_detection_tutorial.ipynb
# What model to download. MODEL_NAME = 'ssd_mobilenet_v1_coco_2017_11_17' MODEL_FILE = MODEL_NAME + '.tar.gz' DOWNLOAD_BASE = 'http://download.tensorflow.org/models/object_detection/' # Path to frozen detection graph. This is the actual model that is used for the object detection. PATH_TO_CKPT = MODEL_NAME + '/frozen_inference_graph.pb' # List of the strings that is used to add correct label for each box. PATH_TO_LABELS = os.path.join('data', 'mscoco_label_map.pbtxt') NUM_CLASSES = 90Now the cell clearly says the
.pbfilename which is/frozen_inference_graph.pb- So you already have the 
.pbfile why do you want to convert ?? - Anyways you can refer thsi link for freezing the graph: https://github.com/jayshah19949596/Tensorboard-Visualization-Freezing-Graph
 - you need to use 
tensorflow.python.tools.freeze_graph()function to convert your.ckptfile to.pbfile The below code line shows how you do it
freeze_graph.freeze_graph(input_graph_path, input_saver_def_path, input_binary, input_checkpoint_path, output_node_names, restore_op_name, filename_tensor_name, output_graph_path, clear_devices, initializer_nodes)- input_graph_path : is the path to 
.pbfile where you will write your graph and this.pbfile is not frozen. you will usetf.train.write_graph()to write the graph - input_saver_def_path : you can keep it an empty string
 - input_binary : it is a boolean value keep it false so that the file genertaed is not binary and human readable
 - input_checkpoint_path : path to the 
.ckpt file - output_graph_path : path where you want to write you 
pbfile - clear_devices : boolean value ... keep it False
 - output_node_names : explicit tensor node names that you want to save
 - restore_op_name : string value that should be "save/restore_all"
 - filename_tensor_name = "save/Const:0"
 - initializer_nodes = ""
 
- input_graph_path : is the path to 
 
        Jai
        
- 3,211
 - 2
 - 17
 - 26
 
- 
                    1I don't understand `freeze_graph`. You're saying it converts a `.ckpt` file to a `.pb` file, but `input_graph_path` is a path to a pre-existing `.pb` file? Where does that come from? – jss367 Aug 14 '19 at 14:57