/YOLO-NAS-onnxruntime

This repo provides the C++ implementation of YOLO-NAS based on ONNXRuntime for performing object detection in real-time.Support float32/float16/int8 inference.

Primary LanguageC++GNU General Public License v3.0GPL-3.0

YOLO-NAS-OnnxRuntime (FP32/FP16/INT8)

C++ Python OnnxRuntime Markdown Visual Studio Code Linux Cmake

This repo provides the C++ implementation of YOLO-NAS based on ONNXRuntime for performing object detection in real-time.

➤ Contents

  1. Dependecies

  2. Build

  3. Examples

  4. Demo

  5. References

  6. License

➤ Dependecies

  • Python Install :

    Quick installation from SuperGradients package

      pip install super_gradients==3.1.1
    
  • C++ Install :

    • OpenCV 4.x
    • ONNXRuntime 1.10+
    • OS: Tested on Ubuntu 20.04 and Apple Silicon (M1)
    • CUDA 11+ [Optional]

➤ Build

Rapidly build the project you can run the following commands:

# You can change ONNXRUNTIME_VERSION="x.x.x" in line 4.

./build.sh

If you want to use your own onnxruntime version, decompress the tgz library of onnxruntime :

onnxruntime repo: https://github.com/microsoft/onnxruntime/tags

tar zxvf onnxruntime-linux-x64-gpu-1.10.0.tgz

Next, don't forget to change ONNXRUNTIME_DIR cmake option:

mkdir build && cd build
cmake .. -D ONNXRUNTIME_DIR=path_to_onnxruntime -DCMAKE_BUILD_TYPE=Release
cmake --build .

➤ Examples

  • Comvert Pytorch to ONNX model :

    # default coco model
    python3 convertPytorchToONNX.py --input_model yolo_nas_s --output_dir ./models --img-size 640 640 
    
    # your custom model
    python3 convertPytorchToONNX.py --input_model yolo_nas_s --output_dir ./models --img-size 640 640 --checkpoint_path <path-to-pth-model> --class_names <path-to-names-file>
    

    Description of all arguments:

    • --input_model : Type contains { yolo_nas_s / yolo_nas_m / yolo_nas_l }

    • --img-size : Set model input size (h, w)

    • --output_dir : Directory for saving files, none means using the same path as the input model

    • --half : Convert fp32 to fp16 model.

      [ Custom Model Args ]

    • --checkpoint_path : The path with save the trained pth model

    • --class_names : The path to class names file

      [ PTQ Args ]

    • --int8 : Conver to int8.

    • --calib_image_dir : if None will use dynamic quantization.


    YOLO-NAS ~0.5 mAP by official information:
    Model mAP Latency (ms)
    YOLO-NAS S 47.5 3.21
    YOLO-NAS M 51.55 5.85
    YOLO-NAS L 52.22 7.87
    YOLO-NAS S INT-8 47.03 2.36
    YOLO-NAS M INT-8 51.0 3.78
    YOLO-NAS L INT-8 52.1 4.78
  • Run webcam source from CLI :

    ./demo --model_path ../models/yolo_nas_s.onnx --source 0 --class_names ../models/coco.names --gpu
  • Run video source from CLI :

    ./demo --model_path ../models/yolo_nas_s.onnx --source ../demo/video.mp4 --class_names ../models/coco.names --gpu
  • Run image source from CLI :

    ./demo --model_path ../models/yolo_nas_s.onnx --source ../demo/traffic.jpg --class_names ../models/coco.names --gpu

➤ Demo

➤ References

➤ License

WiFi Analyzer is licensed under the GNU General Public License v3.0 (GPLv3).

GPLv3 License key requirements :

  • Disclose Source
  • License and Copyright Notice
  • Same License
  • State Changes