Win10環境下yolov8快速設定與測試

2023-01-31 15:01:05

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

如下圖訓練狀態:

五、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