Thursday, April 4, 2019

Tensorflow Object Detection API - Inference

After you get a machine learning model by training on Tensorflow, you can run that model and receive the detection result. The source code is here on Github. (https://github.com/koheikawata/objectdetectiontest). Below are examples of inputs and outputs of "object_detection_inference_test1.py"




Set up paths of label, model, and input image

In this example, THRESHOLD allows only inference results higher than 0.6 to be responded

Load image file

image

image_np

image_np_expanded

Load model file
If you do not load a model file, ops is null.

You have to load a model file and then get tensor names.
out:

Then you are going to create dictionary of Tensor to input into tf.Session().run.

Run inference

Run inference. feed_dict allows to input values. In this case, feed_dict inputs tensor_image made from the test image file.


Change data type of the inference result


Get labels and create a json file
If the example of pascal_label_map.pbtxt is like below,

category_index becomes like this

And then this creates a json file for response