Win10环境下yolov8(ultralytics) 快速配置与测试

时间:2023-01-31 14:10:41

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

一、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为例子,原图图下图:

Win10环境下yolov8(ultralytics) 快速配置与测试

我们将图像和yolov8n.pt放到路径:d:/Data/,推理:

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

效果如图:

Win10环境下yolov8(ultralytics) 快速配置与测试

三、训练

3.1 快速训练coco128数据集

在win10下,创建路径:D:\CodePython\yolov8,将这个5Mb的数据集下载并解压在目录,coco128数据集快速下载:https://share.weiyun.com/C0noWh5W

如下图:

Win10环境下yolov8(ultralytics) 快速配置与测试

 

 

 新建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

如下图训练状态:

Win10环境下yolov8(ultralytics) 快速配置与测试

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

如下图预测窗口打印: 

Win10环境下yolov8(ultralytics) 快速配置与测试

四、导出onnx

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

Win10环境下yolov8(ultralytics) 快速配置与测试

五、yolov8的tensorrt部署加速

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)的新能表现:

model video resolution model input size GPU Memory-Usage GPU-Util
yolov8n 1920x1080 8x3x640x640 1093MiB/7982MiB 14%

下图是yolov8n的运行时间开销,单位是ms:
Win10环境下yolov8(ultralytics) 快速配置与测试

更多TensorRT-Alpha测试录像在B站视频:
B站:YOLOv8n
B站:YOLOv8s

Win10环境下yolov8(ultralytics) 快速配置与测试

附录

更多训练指引,请看官方文档。

  • # ???? yolov8 官方仓库: https://github.com/ultralytics/ultralytics
  • # ???? yolov8 官方中文教程:
  • # ???? yolov8 官方训练指引: https://docs.ultralytics.com/reference/base_trainer/
  • # ???? yolov8 官方快速教程: https://docs.ultralytics.com/quickstart/