实现TensorRT加速Pytorch模型的过程(Yolov5为例)

一、环境:

  系统:ubuntu16.04

  显卡:GeForce MX250

  显卡驱动:460.32.03

  CUDACUDNN版本:cuda10.2.89, cudnn8.1

  TensorRT版本:7.2.3.4 

  Cmake版本:3.20

  Gcc & G++版本:7.6.5

二、安装过程(以Yolov5为例)

  1、首先安装TensorRT

    参考:https://zhuanlan.zhihu.com/p/344810135

    注意点:如果在安装后import tensorrt出现ImportError: libxxx.so.10.2: cannot open shared object file: No such file or directory,原因是TensorRT的链接库路径丢失,利用ldconfig检查,并且利用sudo ln -s xxxxxxxxxxxxxxxxx.so.10.2 xxxxxxxxxxxxx.so,建立软链接

    其余注意点有,cuda版本至少10.0以上,cudnn版本根据tensorrt的版本选择,并且显卡驱动的版本支持当前的cuda等环境的要求。

  2、安装转化的源代码(https://github.com/enazoe/yolo-tensorrt)

    (1) 建立一个文件夹:mkdir yolo_tensorrt_test

    (2) 进入文件夹后

      git clone https://github.com/ultralytics/yolov5.git

      git clone https://github.com/enazoe/yolo-tensorrt.git

    (3) yaml2cfg.py将脚本复制到yolov5根目录,并生成cfgweigths文件

      cp yolo-tensorrt/scripts/yaml2cfg.py yolov5/

      cd yolov5

      python yaml2cfg.py

      cd ..

      mv yolov5/models/yolov5s.cfg yolo-tensorrt/configs/yolov5-4.0

      mv yolov5/weights/yolov5s.weights yolo-tensorrt/configs/yolov5-4.0

    (4) 进入yolo-tensorrt文件夹

      首先更改Cmakelists.txt文件(很重要!很重要!很重要!)

      在#detector lib (cuda)之前,添加代码

        include_directories(/home/qsm16/TensorRT-7.2.3.4/include/)

        link_directories(/home/qsm16/TensorRT-7.2.3.4/lib/)

        link_libraries(nvinfer nvinfer_plugin nvparsers nvonnxparser myelin)

        (并且在build前,应当保证gccg++的版本要求)

      然后编译源码      

        mkdir build && cd build

        cmake ..

        make

        ./yolo_trt

      完成安装!

    上述过程亲测有效,另外有其他问题欢迎一起探讨,并且该版本代码为c++,另有python版本的实现,因为有完整的过程我仅将github链接放在这里供大家参考

    https://github.com/wang-xinyu/tensorrtx

原文链接: https://www.cnblogs.com/qsm2020/p/14798265.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    实现TensorRT加速Pytorch模型的过程(Yolov5为例)

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/210777

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 上午12:29
下一篇 2023年2月13日 上午12:29

相关推荐