Giter Club home page Giter Club logo

object-detection-tf's Introduction

Running TF object detection model using onnxruntime

Installation

Install python 3+ dependencies.

tensorflow: 1.12.0
onnx: 1.6.0
tf2onnx: 1.5.5
onnxruntime: 1.1.0

TF to ONNX

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.

Python script

Run python script object_detection_image_onnx.py to test converted onnx model.

Figure 1. Python example

C# application

Build C# source code and run application.

Figure 2. C# example

References

[1] TensorFlow detection model zoo.
[2] Tutorial: how to convert them to ONNX and run them under onnxruntime.
[3] Microsoft: ONNX Runtime C# API.

object-detection-tf's People

Contributors

asiryan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

object-detection-tf's Issues

Testing with own ONNX model: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Invalid Feed Input Name:image_tensor:0

This looked like a very easy and nice way to test a onnx file quickly, however I get this error when testing out
object_detection_image_onnx.py. I made sure to update the params for my own model!

Traceback (most recent call last):
  File "object_detection_image_onnx.py", line 22, in <module>
    result = sess.run(outputs, {"image_tensor:0": img_data})
  File "/home/robyer1/.local/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 124, in run
    return self._sess.run(output_names, input_feed, run_options)
onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Invalid Feed Input Name:image_tensor:0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.