Win10環境下yolov8快速配置與測試

FeiYull發表於2023-01-31

win10下親測有效!(如果想在tensorrt+cuda下部署yolov8,直接看第五5章)

yolov8 官方倉庫: https://github.com/ultralytics/ultralytics

一、win10下建立yolov8環境

# 注:python其他版本在win10下,可能有坑,我已經替你踩坑了,這裡python3.9親測有效
conda create -n yolov8 python=3.9 -y
conda activate yolov8
pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple

二、推理影像

模型下載地址:

# download offical weights(".pt" file)
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8s.pt
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8l.pt
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x.pt
https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8x6.pt

這裡下載yolov8n為例子,原圖圖下圖:

我們將影像和yolov8n.pt放到路徑:d:/Data/,推理:

yolo predict model="d:/Data/yolov8n.pt" source="d:/Data/6406407.jpg"

效果如圖:

三、訓練

3.1 快速訓練coco128資料集

在win10下,建立路徑:D:\CodePython\yolov8,將這個5Mb的資料集下載並解壓在目錄,coco128資料集快速下載:https://share.weiyun.com/C0noWh5W

如下圖:

 新建train.py檔案,程式碼如下:、

from ultralytics import YOLO
 
# Load a model
# yaml會自動下載
model = YOLO("yolov8n.yaml")  # build a new model from scratch
model = YOLO("d:/Data/yolov8n.pt")  # load a pretrained model (recommended for training)
 
# Train the model
results = model.train(data="coco128.yaml", epochs=100, imgsz=640)

訓練指令:

 python train.py

如下圖訓練狀態:

3.2 預測

新建predict.py檔案,程式碼如下:

from ultralytics import YOLO
 
# Load a model
model = YOLO("d:/Data/yolov8n.pt")  # load an official model
 
# Predict with the model
results = model("d:/Data/6406407.jpg")  # predict on an image

預測指令:

 python predict.py

如下圖預測視窗列印: 

四、匯出onnx

pip install onnx
yolo mode=export model="d:/Data/yolov8n.pt" format=onnx dynamic=True

五、yolov8的tensorrt部署加速

《YOLOV8部署保姆教程》:https://www.cnblogs.com/feiyull/p/17066486.html

TensorRT-Alpha基於tensorrt+cuda c++實現模型end2end的gpu加速,支援win10、linux,在2023年已經更新模型:YOLOv8, YOLOv7, YOLOv6, YOLOv5, YOLOv4, YOLOv3, YOLOX, YOLOR,pphumanseg,u2net,EfficientDet。
Windows10教程正在製作,可以關注TensorRT-Alphahttps://github.com/FeiYull/TensorRT-Alpha

?快速看看yolov8n 在移動端RTX2070m(8G)的新能表現:

modelvideo resolutionmodel input sizeGPU Memory-UsageGPU-Util
yolov8n 1920x1080 8x3x640x640 1093MiB/7982MiB 14%

下圖是yolov8n的執行時間開銷,單位是ms:
在這裡插入圖片描述

更多TensorRT-Alpha測試錄影在B站影片:
B站:YOLOv8n
B站:YOLOv8s

在這裡插入圖片描述

附錄

更多訓練指引,請看官方文件。

  • # ? yolov8 官方倉庫: https://github.com/ultralytics/ultralytics
  • # ? yolov8 官方中文教程:https://github.com/ultralytics/ultralytics/blob/main/README.zh-CN.md
  • # ? yolov8 官方訓練指引: https://docs.ultralytics.com/reference/base_trainer/
  • # ? yolov8 官方快速教程: https://docs.ultralytics.com/quickstart/

 

相關文章