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

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

Win10环境下yolov8快速配置与测试_第1张图片

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

推理:

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

效果如图:

Win10环境下yolov8快速配置与测试_第2张图片

三、训练

3.1 快速训练coco128数据集

在win10下,创建路径:D:\CodePython\yolov8,将这个5Mb的数据集下载并解压在目录,

coco128数据集下载地址(别担心,免费白嫖):文件分享

如下图:

Win10环境下yolov8快速配置与测试_第3张图片

 新建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快速配置与测试_第4张图片

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

如下图预测窗口打印: 

e4f9da80bf504ca7a01c5b2a85323b7c.jpeg

四、导出onnx

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

Win10环境下yolov8快速配置与测试_第5张图片

 五、yolov8的tensorrt部署加速

《YOLOV8部署保姆教程》
https://blog.csdn.net/m0_72734364/article/details/128758544?spm=1001.2014.3001.5501

TensorRT-Alpha基于tensorrt+cuda c++实现模型end2end的gpu加速,支持win10、linux,在2023年已经更新模型:YOLOv8, YOLOv7, YOLOv6, YOLOv5, YOLOv4, YOLOv3, YOLOX, YOLOR,pphumanseg,u2net,EfficientDet。
TensorRT-Alpha:https://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:
51ed467668e24b8c982008903733a6e2.jpeg#pic_center

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

78afd19e93464dd8bf8c4d12cf129147.jpeg#pic_center

附录:

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

  • #  yolov8 官方仓库: https://github.com/ultralytics/ultralytics
    #  yolov8 官方中文教程:ultralytics/README.zh-CN.md at main · ultralytics/ultralytics · GitHub
    #  yolov8 官方训练指引: https://docs.ultralytics.com/reference/base_trainer/
    #  yolov8 官方快速教程: https://docs.ultralytics.com/quickstart/

你可能感兴趣的:(TensorRT-Alpha,YOLO,深度学习,目标检测,计算机视觉)