Yolov5 c++ and onnxruntime linux ubutnu deployment implementation

yolov5_cpp project description document

This project is an application for object detection using the YOLOv5 model, which can process pictures and videos.
At the same time, it uses the LIME algorithm (Low-light Image Enhancement) to enhance the quality of the input image.
During processing, this program will display three windows: the original input frame, the frame after target detection, and the LIME-enhanced detection frame.
C++ YOLO v5 ONNX Runtime inference code for object detection.

Struct

├── build.sh             # 构建脚本
├── CMakeLists.txt       # CMake构建文件
├── images               # 示例图片和视频文件
├── include              # 头文件
│   ├── cmdline.h        # 命令行解析
│   ├── detector.h       # YOLO检测器定义
│   ├── lime.h           # LIME算法定义
│   ├── utils.h          # 实用工具函数
│   └── visualizer.h     # 可视化工具函数
├── lime                 # LIME算法相关文件
├── models               # 预训练YOLOv5模型和类别名称文件
├── README.md            # 项目说明文档
└── src                  # 源代码文件
    ├── add_fps.cpp      # 添加FPS显示功能
    ├── add_lime.cpp     # 添加LIME功能
    ├── add_thread.cpp   # 添加多线程功能
    ├── detector.cpp     # YOLO检测器实现
    ├── lime.cpp         # LIME算法实现
    ├── main.cpp         # 主程序
    ├── utils.cpp        # 实用工具函数实现
    └── visualizer.cpp   # 可视化工具函数实现

Dependecies:

  • OpenCV 4.x
  • ONNXRuntime 1.12.0
  • OS: Tested on Windows 10 and Ubuntu 20.04
  • CUDA 11+ [Optional]

Build

To build the project and run the following commands

cd yolov5_cpp
./build.sh
cd build

or

mkdir build
cd build
cmake
make

Run

Before running the executable you should convert your PyTorch model to ONNX if you haven’t done it yet. Check the official tutorial.

On Windows: to run the executable you should add OpenCV and ONNX Runtime libraries to your environment path or put all needed libraries near the executable (onnxruntime.dll and opencv_world.dll).

Run from CLI,the --gpu(option):

  • -m or --model_path: path to the ONNX model file
  • -c or --class_names: path to class name file
  • -i or --input: Enter the path to the image or video file
  • –gpu: (optional) Use GPU acceleration
./build.sh
cd build
./yolov5_cpp -m ../models/yolov5s.onnx -c ../models/coco.names -i ../images/bus.jpg --gpu
# On Windows ./yolo_ort.exe with arguments as above

References

  • YOLO v5 repo: https://github.com/ultralytics/yolov5
  • YOLOv5 Runtime Stack repo: https://github.com/zhiqwang/yolov5-rt-stack
  • ONNXRuntime Inference examples: https://github.com/microsoft/onnxruntime-inference-examples

Guess you like

Origin blog.csdn.net/weixin_42065767/article/details/131157940
Recommended