项目简介
本项目基于NVIDIA TensorRT框架实现Yolo目标检测模型,支持YoloV3、YoloV4、YoloV5等多个版本模型。它封装了NVIDIA官方的Yolo - TensorRT实现,提供从模型加载、推理到结果解码的完整流程。支持FP32、FP16和INT8精度的模型推理,能在Windows、Ubuntu以及Jetson平台上高效运行。
项目的主要特性和功能
- 多版本Yolo模型支持:涵盖YoloV3、YoloV4、YoloV5及其变体,如YoloV4 - tiny、YoloV5s、YoloV5m等。
- 多精度推理:支持FP32、FP16和INT8精度的模型推理,适配不同硬件平台。
- 跨平台支持:可在Windows 10、Ubuntu 18.04以及Jetson平台(如Jetson Nano、Jetson Xavier NX)运行。
- 批量推理:支持批量图像输入,提高推理效率。
- 高性能推理:在Jetson平台上,YoloV3 - 416x416模型的推理时间低至35ms(INT8精度)。
- 易用性:提供C++ API,便于集成到其他项目,支持DLL和SO库的生成。
安装使用步骤
环境准备
- Windows 10:安装TensorRT 7.1.3.4、CUDA 11.0、cuDNN 8.0、OpenCV 4以及Visual Studio 2015。
- Ubuntu 18.04 / Jetson平台:安装TensorRT、CUDA、cuDNN以及OpenCV。
项目构建
Windows 10
- 打开项目中的
sln/sln.sln
文件。 - 构建
dll
项目以生成Yolo检测器的DLL文件。 - 构建
demo
项目以测试生成的DLL文件。
Ubuntu & Jetson平台
- 复制项目仓库:
bash cd yolo - tensorrt/
- 创建并进入
build
目录:bash mkdir build cd build/
- 使用CMake构建项目:
bash cmake .. make
- 运行示例程序:
bash ./yolo - trt
模型推理
- 准备模型文件:确保准备好Yolo模型的
.weights
和.cfg
文件(对于YoloV5,需要.pt
和.yaml
文件)。 - 配置检测器:通过
Config
结构体配置模型路径、推理精度、GPU ID等参数。 - 初始化检测器:使用
Detector
类的init
方法初始化检测器。 - 执行推理:调用
detect
方法进行批量图像推理,获取检测结果。
示例代码
```c++
include "detector.h"
int main() { Detector detector; Config config; config.file_model_cfg = "configs/yolov4.cfg"; config.file_model_weights = "configs/yolov4.weights"; config.inference_precison = INT8;
detector.init(config);
std::vector<cv::Mat> images;
std::vector<BatchResult> results;
detector.detect(images, results);
return 0;
} ```
下载地址
点击下载 【提取码: 4003】【解压密码: www.makuang.net】