Search code examples
tensorflowobject-detection

Use TensorFlow model for object detection after training


I followed this tutorial to train a custom object detector. I have followed the tutorial successfully to the end and exported the trained inference graph. This step states:

Once your training job is complete, you need to extract the newly trained inference graph, which will be later used to perform the object detection.

I now have a directory structure under the training demo:

training_demo
  \ trained-inference-graphs
    \ output_inference_Graph_v1.pb
       \ saved_model
          \ variables
          - saved_model.pb
       - checkpoint
       - frozen_inference_graph.pb
       - model.ckpt.data-00000-of-00001
       - model.ckpt.index
       - model.ckpt.meta
       - pipeline.config

The problem is that I cannot find any instructions on how to use this with new images to detect the objects in them?

I want to load this newly trained model and pass it some images to detect objects.


Solution

  • the easiest way to learn this, is by going through the Jupyter Notebook tutorial, included in Tensorflow.

    You find it in Tensorflow -> Models -> Research -> Object Detection -> object_detection_tutorial.ipynb, or through the link here.

    Then you need to revise the Notebook a bit. Here you will need to change:

    • Remove the "Download Model" section.

    • Change the path to your Frozen Inference Graph from your retrained model.

    • Change the label_map.pbtxt to your retrained labels.

    • Mark your path to your test images and adjust according to their file extensions. They follow the pattern "image1.jpg", "image2.jpg" etc. by default

    Voila, you're done. You can test it on a pre-trained model from the Tensorflow Detection Zoo first if you want, by using the default script.