yolov8實戰——yolov8TensorRT部署(python推理)(保姆教學)
- 一 、準備好代碼和環境
- 安裝TensorRt
- 下載代碼和安裝環境
- 部署和推理
- 構建ONNX
- 構建engine
- 無torch推理
- torch推理
最近用到yolov8,但是尋找了一圈才找到了yolov8最佳的部署方法,限于python,所以在此進行總結記錄,方便眾人,看完此篇,不會純屬自己問題,與我無瓜0.0
一 、準備好代碼和環境
先創建一個環境吧:
conda create -n trt python=3.9
安裝TensorRt
TensorRt下載鏈接
下載之后,解壓,吧其中的bin、include、lib的文件都放到安裝cuda的對應文件里即可,然后激活環境trt,pip install python/tensorrt-8.6.1-cp39-none-win_amd64.whl
下載代碼和安裝環境
git clone https://github.com/triple-Mu/YOLOv8-TensorRT.git
cd YOLOv8-TensorRT
pip install -r requirements.txt
部署和推理
構建ONNX
python export-det.py --weights weights/v8s4/weights/last.pt --iou-thres 0.65 --conf-thres 0.25 --topk 100 --opset 14 --input-shape 1 3 640 640 --device cuda:0 --sim
構建engine
這是集成了nms,速度更快
python build.py --weights weights/v8s-faster-twoc-Lcls-coco802/weights/best.onnx --iou-thres 0.65 --conf-thres 0.25 --topk 100 --device cuda:0 --fp16
無torch推理
python infer-det-without-torch.py --engine best.engine --imgs data --show --method pycuda
torch推理
python infer-det.py --engine best.engine --imgs data --show