Step by Step TensorFlow Object Detection API Tutorial — Part 5: Saving and Deploying a Model

Daniel Stang
Oct 25, 2017 · 2 min read

At this point in the tutorial you have selected a pre-trained object detection model, adapted an existing dataset or created your own and turned it into a TFRecord file, modified a model config file, and started training. However, you now need to save your model and deploy it in your project.

Saving a Checkpoint Model (.ckpt) as a .pb File

Navigate back to your TensorFlow object detection folder and copy the file into the folder containing your model config file.

python --input_type image_tensor --pipeline_config_path ./rfcn_resnet101_coco.config --trained_checkpoint_prefix ./models/train/model.ckpt-5000 --output_directory ./fine_tuned_model

This will create a new directory fine_tuned_model, inside of which will be your model named frozen_inference_graph.pb.

Using the Model in Your Project

The project that I’ve been working on throughout this guide is creating a traffic light classifier. In Python I implemented this classifier as a class. In the initialization part of the class I created a TensorFlow session so that it wouldn’t need to be created every time the classification was required.

Within that class I created a function that runs the classification on an image and returns the bounding boxes, scores, and class of whatever is classified in the image.

At this point you will want to filter the results lower than a specified score threshold. The results are automatically sorted from highest score to lowest so this is fairly easy. With your classification results returned by the function above, that’s it, your done!

Below you can see my traffic light classifier in action.

Traffic Light Classifier for the Udacity Self-Driving Car Nanodegree Final Project

I originally created this tutorial because I struggled to find information on how to use certain parts of the Object Detection API. I hope that by reading this guide I’ve enabled you to get your project up and running faster so that you can focus more time on what you are truly interested in!

Daniel Stang

Written by