Install python 3+ dependencies.
tensorflow: 1.12.0
onnx: 1.6.0
tf2onnx: 1.5.5
onnxruntime: 1.1.0
Download TF object detection model trained on COCO dataset from the Model Zoo and convert it to onnx model.
For example download ssd_mobilenet_v1_coco_2018_01_28 and convert it to onnx model from saved_model.pb
python -m tf2onnx.convert
--opset 11
--fold_const
--saved-model ssd_mobilenet_v1_coco_2018_01_28/saved_model/
--output ssd_mobilenet_v1_coco_2018_01_28/model.onnx
or from frozen_inference_graph.pb
python -m tf2onnx.convert
--opset 11
--fold_const
--graphdef ssd_mobilenet_v1_coco_2018_01_28/frozen_inference_graph.pb
--output ssd_mobilenet_v1_coco_2018_01_28/frozen.onnx
--inputs image_tensor:0
--outputs detection_boxes:0,detection_classes:0,detection_scores:0,num_detections:0
For run python and C# examples below download path with already-made ssd_mobilenet_v1_coco_2018_01_28 onnx models and move it to repository root folder.
Run python script object_detection_image_onnx.py to test converted onnx model.
Figure 1. Python example
Build C# source code and run application.
Figure 2. C# example
[1] TensorFlow detection model zoo.
[2] Tutorial: how to convert them to ONNX and run them under onnxruntime.
[3] Microsoft: ONNX Runtime C# API.