Search code examples
pythonpython-3.xtensorflowobject-detection-api

How to get input/output name to create .pb file


I trained a model for object detection API of Tensorflow with my dataset. After saving the model, I got three files:

  • model.ckpt-10000.data-00000-of-00001
  • model.ckpt-10000.meta
  • model.ckpt-10000.index

From these files, I want to create a .pb file. I googled and realized that I can use "freeze_graph.py" that is contained in Tensorflow project. But to use freeze_graph.py, I need input/output names.

Some people suggested to use "summarize_graph tool", but to do so, I need to provide .pb file in the arguments. I need output/input names to create .pb file, so I can't use "summarize_graph tool" as I don't have .pb file yet.

I saw this question: How do you get the name of the tensorflow output nodes in a Keras Model?
But it just gave me thousands of possible output/input node names.

So my question is:
How do you get input/output node without .pb file?


Solution

  • I found that there is a tool to freeze graph for object detection API which can be used without input/output name. See here for the command. It's like this:

    # From tensorflow/models/research/
    python object_detection/export_inference_graph.py \
        --input_type image_tensor \
        --pipeline_config_path ${PIPELINE_CONFIG_PATH} \
        --trained_checkpoint_prefix ${TRAIN_PATH} \
        --output_directory output_inference_graph.pb
    

    Then I got a .pb file from these three files: model.ckpt-10000.data-00000-of-00001, model.ckpt-10000.meta, model.ckpt-10000.index.

    Or if you already have a .pb file, you can use this: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tools/graph_transforms/README.md#inspecting-graphs