11

Using Javascript to load ONNX model for Object Detection job

 1 year ago
source link: https://donghao.org/2023/07/28/using-javascript-to-load-onnx-model-for-object-detection-job/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Using Javascript to load ONNX model for Object Detection job

Although having used the YOLOv5 model several times, I haven’t used its corresponding ONNX model before. This time, I met a use case to run its ONNX model using Javascript.

To learn and debug the code, I installed node.js and started my Javascript trip. This snippet helps me a lot to understand the Non-Max Suppression algorithm again (I used NMS algo many years). After studying it and also the implementation in the YOLOv5, I finally knocked together the Javascript code to use the ONNX model of YOLOv5 to detect objects:

https://github.com/RobinDong/onnx_js/blob/main/detect.js

Why the “YOLOV5S_CLASSES” is 85? That’s because in YOLO series it uses the first four floats as coordinates of boxes (center x, center y, width, height), the fifth as “object confidence”, and the left 80 floats as “class confidence”.

For anyone who is interested in it, you could use the below steps to run:

  1. Install node.js on your computer or laptop
  2. Run npm install fs inkjet onnxruntime-node to install js packages
  3. Run node detect.js lorikeet.jpg to detect objects in the image “lorikeet.jpg” and output to file “output.txt”
  4. Run python3 draw.py lorikeet.jpg to show the image of the result by using data in “output.txt”

Hope it could be useful for someone.

Related Posts

July 28, 2023 - 4:00 RobinDong machine learning
YOLOv5
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK