# YOLOv5
TensorRTx inference code base for [ultralytics/yolov5](https://github.com/ultralytics/yolov5).
## Contributors
<a href="https://github.com/wang-xinyu"><img src="https://avatars.githubusercontent.com/u/15235574?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/BaofengZan"><img src="https://avatars.githubusercontent.com/u/20653176?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/upczww"><img src="https://avatars.githubusercontent.com/u/16224249?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/cesarandreslopez"><img src="https://avatars.githubusercontent.com/u/14029177?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/makaveli10"><img src="https://avatars.githubusercontent.com/u/39617050?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/priteshgohil"><img src="https://avatars.githubusercontent.com/u/43172056?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/rymzt"><img src="https://avatars.githubusercontent.com/u/3270954?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/AsakusaRinne"><img src="https://avatars.githubusercontent.com/u/47343601?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/freedenS"><img src="https://avatars.githubusercontent.com/u/26213470?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/smarttowel"><img src="https://avatars.githubusercontent.com/u/1128528?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/wwqgtxx"><img src="https://avatars.githubusercontent.com/u/582584?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/adujardin"><img src="https://avatars.githubusercontent.com/u/12609780?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/jow905"><img src="https://avatars.githubusercontent.com/u/19189198?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/CristiFati"><img src="https://avatars.githubusercontent.com/u/29705787?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/HaiyangPeng"><img src="https://avatars.githubusercontent.com/u/46739135?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/Armassarion"><img src="https://avatars.githubusercontent.com/u/33727511?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/xupengao"><img src="https://avatars.githubusercontent.com/u/51817015?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/liuqi123123"><img src="https://avatars.githubusercontent.com/u/46275888?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/ASONG0506"><img src="https://avatars.githubusercontent.com/u/26050577?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/bobo0810"><img src="https://avatars.githubusercontent.com/u/26057879?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/Silmeria112"><img src="https://avatars.githubusercontent.com/u/16464837?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/LW-SCU"><img src="https://avatars.githubusercontent.com/u/28128257?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/AdanWang"><img src="https://avatars.githubusercontent.com/u/32757980?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/triple-Mu"><img src="https://avatars.githubusercontent.com/u/92794867?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/xiang-wuu"><img src="https://avatars.githubusercontent.com/u/107029401?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/uyolo1314"><img src="https://avatars.githubusercontent.com/u/101853326?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/Rex-LK"><img src="https://avatars.githubusercontent.com/u/74702576?s=48&v=4" width="40px;" alt=""/></a>
<a href="https://github.com/PrinceP"><img src="https://avatars.githubusercontent.com/u/10251537?s=48&v=4" width="40px;" alt=""/></a>
## Different versions of yolov5
Currently, we support yolov5 v1.0, v2.0, v3.0, v3.1, v4.0, v5.0, v6.0, v6.2, v7.0
- For yolov5 v7.0, download .pt from [yolov5 release v7.0](https://github.com/ultralytics/yolov5/releases/tag/v7.0), `git clone -b v7.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v7.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v7.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v7.0/yolov5)
- For yolov5 v6.2, download .pt from [yolov5 release v6.2](https://github.com/ultralytics/yolov5/releases/tag/v6.2), `git clone -b v6.2 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v6.2 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v6.2](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v6.2/yolov5)
- For yolov5 v6.0, download .pt from [yolov5 release v6.0](https://github.com/ultralytics/yolov5/releases/tag/v6.0), `git clone -b v6.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v6.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v6.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v6.0/yolov5).
- For yolov5 v5.0, download .pt from [yolov5 release v5.0](https://github.com/ultralytics/yolov5/releases/tag/v5.0), `git clone -b v5.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v5.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v5.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v5.0/yolov5).
- For yolov5 v4.0, download .pt from [yolov5 release v4.0](https://github.com/ultralytics/yolov5/releases/tag/v4.0), `git clone -b v4.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v4.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v4.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v4.0/yolov5).
- For yolov5 v3.1, download .pt from [yolov5 release v3.1](https://github.com/ultralytics/yolov5/releases/tag/v3.1), `git clone -b v3.1 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v3.1 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v3.1](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v3.1/yolov5).
- For yolov5 v3.0, download .pt from [yolov5 release v3.0](https://github.com/ultralytics/yolov5/releases/tag/v3.0), `git clone -b v3.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v3.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v3.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v3.0/yolov5).
- For yolov5 v2.0, download .pt from [yolov5 release v2.0](https://github.com/ultralytics/yolov5/releases/tag/v2.0), `git clone -b v2.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v2.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v2.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v2.0/yolov5).
- For yolov5 v1.0, download .pt from [yolov5 release v1.0](https://github.com/ultralytics/yolov5/releases/tag/v1.0), `git clone -b v1.0 https://github.com/ultralytics/yolov5.git` and `git clone -b yolov5-v1.0 https://github.com/wang-xinyu/tensorrtx.git`, then follow how-to-run in [tensorrtx/yolov5-v1.0](https://github.com/wang-xinyu/tensorrtx/tree/yolov5-v1.0/yolov5).
## Config
- Choose the YOLOv5 sub-model n/s/m/l/x/n6/s6/m6/l6/x6 from command line arguments.
- Other configs please check [src/config.h](src/config.h)
## Build and Run
### Detection
1. generate .wts from pytorch with .pt, or download .wts from model zoo
```
git clone -b v7.0 https://github.com/ultralytics/yolov5.git
git clone -b yolov5-v7.0 https://github.com/wang-xinyu/tensorrtx.git
cd yolov5/
wget https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt
cp [PATH-TO-TENSORRTX]/yolov5/gen_wts.py .
python gen_wts.py -w yolov5s.pt -o yolov5s.wts
# A file 'yolov5s.wts' will be generated.
```
2. build tensorrtx/yolov5
yolov5 tensorrt c++部署

在IT领域,尤其是在计算机视觉和深度学习应用中,模型部署是一个关键环节,它涉及到将训练好的模型集成到实际系统中,以实现高效、实时的预测。"yolov5 tensorrt c++部署"是一个这样的实践,它结合了流行的对象检测模型YOLOv5和NVIDIA的高性能推理框架TensorRT,并通过C++接口进行实现。以下是对这个主题的详细解释:
YOLOv5(You Only Look Once version 5)是一种基于深度学习的实时目标检测算法,以其快速和精确而受到广泛关注。该模型通过单次前向传播就能同时检测图像中的多个目标,具有较高的检测速度和准确率。YOLOv5的转换过程通常包括将训练好的PyTorch模型导出为ONNX(Open Neural Network Exchange)格式,然后使用NVIDIA的TensorRT工具对ONNX模型进行优化,生成`.engine`文件。这个`.engine`文件是针对特定硬件平台(如GPU)优化的二进制文件,包含了模型的推理逻辑,可以被C++ API直接加载和执行。
TensorRT是一个高性能的深度学习推理(Inference)引擎,它针对NVIDIA GPU进行了优化,能有效减少推理时间,提高模型运行效率。与ONNXRuntime等其他推理框架相比,TensorRT通过动态层优化、精度控制、多精度支持等功能,能够进一步挖掘硬件潜能,特别是在处理复杂模型时,其速度优势更为显著。在C++环境中部署TensorRT模型,可以利用其丰富的API和库,实现高效、低延迟的模型预测。
在C++部署过程中,开发者需要编写代码来加载`.engine`文件,初始化TensorRT运行时环境,创建执行上下文,分配输入和输出张量,以及执行推理任务。具体步骤包括:
1. 初始化TensorRT库和构建引擎:使用`IGraphBuilder`构建模型图,通过`ICudaEngine`接口创建和加载`.engine`文件。
2. 创建执行上下文:`IExecutionContext`接口用于执行推理操作,它是模型执行的核心部分。
3. 分配内存:为输入和输出数据分配GPU内存,确保数据在GPU上直接进行读写,减少数据传输开销。
4. 绑定和执行:将输入数据复制到分配的GPU内存,调用`execute()`函数执行推理,获取输出结果。
5. 清理资源:执行完成后,释放内存和关闭执行上下文,释放引擎。
在提供的压缩包文件`yolov5_master`中,可能包含了YOLOv5模型的源码、预训练权重、转换脚本以及相关的C++部署示例。开发者可以通过研究这些内容,了解并实现YOLOv5在TensorRT上的C++部署。
"yolov5 tensorrt c++部署"是深度学习模型落地的重要实践,它结合了高效的模型和高性能的推理引擎,旨在提供在C++环境中快速、准确的目标检测解决方案。对于开发者来说,掌握这一技术有助于提升AI应用的性能和用户体验。


AI小怪兽
- 粉丝: 5w+
最新资源
- 119#三菱PLC与组态王啤酒发酵温度压力控制系统 · PLC编程
- 基于西门子S7-300PLC与组态王的混凝土搅拌站智能配料系统设计与应用 专业版
- 基于西门子S7-300PLC和MCGS组态的热电厂输煤控制系统设计与应用 · MCGS
- 基于三菱PLC和MCGS组态的高效物料自动分拣控制系统设计与应用
- 基于西门子S7-200PLC与组态王的工业锅炉温度控制系统设计与实现
- 西门子S7-200PLC与MCGS6.2在立体仓库控制堆垛书架的应用
- 西门子1200 PLC自动流程程序的三种编写方法及应用
- 西门子S7-200与MCGS组态在汽车自动清洗机控制系统中的应用研究
- 多目标粒子群算法MOPSO的Matlab实现及其在工程优化中的应用 · 多目标优化
- 电力系统仿真:IEEE33节点配电网Simulink模型及其应用
- 西门子S7-200PLC与组态王在温室大棚智能控制系统的应用
- MATLAB实现基于Adaboost与Haar特征的车牌智能检测系统
- 西门子S7-200PLC与MCGS组态联手打造全自动洗衣机智能控制系统 - 通信协议 v4.0
- 基于Swin Transformer的高效图像分类解决方案
- 基于GJO-TCN-BiGRU-Attention的Matlab多变量时间序列预测算法及应用 - 注意力机制
- MATLAB环境下基于改进最大相关峭度解卷积算法的滚动轴承故障诊断技术研究与应用