Yolov5使用TensorRT加速(python篇)/win10/linux
文章目录
前言
使用的是最新的项目,因为新的项目都把代码写好了,直接调用就行了。。。意思操作更无脑了。
前提需要安装TensorRT,使用操作只需要两步。。。麻烦在于环境的安装。
加速流程:导出.engine格式权重文件,加载engine文件自动调用tensorRT。
〇、准备工作:
1.安装TensorRT
参考我另一篇博客超简单安装TensorRT(仅限python)
2.更新项目
使用的最新版的yolov5 6.0或6.1
没更新的更新项目:
git clone https://ghproxy.com/https://github.com/ultralytics/yolov5
3.检查依赖
一定要记得激活环境!
conda actiavate <环境名>
pip install -r requirements.txt
不存在的包会自动更新。
二、导出权重文件
.pt导出为.engine
形式:
python export.py –weights pt权重文件路径 –data 你数据集yaml文件路径 –include engine –device 0
举例:
python export.py --weights models/weights/demo.pt --data data/data.yaml --include engine --device 0
如果导出过程中报错,说哪个库没有装,就去装完库在执行上面导出命令
导出的结果和自己的pt文件在一个路径下。
三、使用tensorRT加速
python detect.py --source xxx/xxx/valid/images --data xxx/xxxx/xx.yaml --weights xxx/xxx/demo.engine --device 0
来源:凌十一