一、環境:
系統:ubuntu16.04
顯卡:GeForce MX250
顯卡驅動:460.32.03
CUDA與CUDNN版本: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根目錄,並生成cfg和weigths文件
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前,應當保證gcc與g++的版本要求)
然后編譯源碼
mkdir build && cd build
cmake ..
make
./yolo_trt
完成安裝!
上述過程親測有效,另外有其他問題歡迎一起探討,並且該版本代碼為c++,另有python版本的實現,因為有完整的過程我僅將github鏈接放在這里供大家參考