随着深度学习技术的不断演进,目标检测领域的明星模型——YOLO系列,已经发展到了第八代,即YOLOv8。这一版本不仅继承了前辈们快速与准确的特点,还实现了功能上的巨大飞跃,成为了一个全能型的视觉AI工具箱,支持检测、分割、姿态估计、跟踪以及分类等多种任务。本文将深入探讨YOLOv8在实际应用中的多样化表现,从基本的目标识别出发,延伸至细致的图像分类与语义分割,展现其在复杂场景下的强大能力。
本系列其他文章
【YOLOv8系列】(一)YOLOv8介绍:实时目标检测的最新突破-CSDN博客
【YOLO8系列】(二)YOLOv8环境配置,手把手嘴对嘴保姆教学-CSDN博客
一.物体检测
物体检测是 YOLOv8 的基础功能,也是最常见的应用场景。通过 YOLOv8,我们可以在图像中快速、准确地识别出不同的目标物体,并标记其位置。图像分类器的输出是单一类别标签和置信度分数。
Model | size (pixels) | mAPval 50-95 | Speed CPU ONNX (ms) | Speed A100 TensorRT (ms) | params (M) | FLOPs (B) |
---|---|---|---|---|---|---|
YOLOv8n | 640 | 37.3 | 80.4 | 0.99 | 3.2 | 8.7 |
YOLOv8s | 640 | 44.9 | 128.4 | 1.20 | 11.2 | 28.6 |
YOLOv8m | 640 | 50.2 | 234.7 | 1.83 | 25.9 | 78.9 |
YOLOv8l | 640 | 52.9 | 375.2 | 2.39 | 43.7 | 165.2 |
YOLOv8x | 640 | 53.9 | 479.1 | 3.53 | 68.2 | 257.8 |
-
数据准备:收集并标注包含目标物体的图像数据集。确保数据集有足够的多样性和数量以提高模型的泛化能力。
-
模型训练:使用 YOLOv8 预训练模型,在目标数据集上进行微调。调整训练参数以达到最佳效果。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n.yaml") # build a new model from YAML
model = YOLO("yolov8n.pt") # load a pretrained model (recommended for training)
model = YOLO("yolov8n.yaml").load("yolov8n.pt") # build from YAML and transfer weights# Train the model
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)
- 结果评估:使用验证集评估模型的识别精度和速度。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n.pt") # load an official model
model = YOLO("path/to/best.pt") # load a custom model# Validate the model
metrics = model.val() # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95
metrics.box.map50 # map50
metrics.box.map75 # map75
metrics.box.maps # a list contains map50-95 of each category
二.图像分类
在目标识别的基础上,YOLOv8 还能够对识别出的目标进行分类。通过结合分类标签,模型可以在检测出目标的同时,给出每个目标所属的类别信息。
Model | size (pixels) | acc top1 | acc top5 | Speed CPU ONNX (ms) | Speed A100 TensorRT (ms) | params (M) | FLOPs (B) at 640 |
---|---|---|---|---|---|---|---|
YOLOv8n-cls | 224 | 69.0 | 88.3 | 12.9 | 0.31 | 2.7 | 4.3 |
YOLOv8s-cls | 224 | 73.8 | 91.7 | 23.4 | 0.35 | 6.4 | 13.5 |
YOLOv8m-cls | 224 | 76.8 | 93.5 | 85.4 | 0.62 | 17.0 | 42.7 |
YOLOv8l-cls | 224 | 78.3 | 94.2 | 163.0 | 0.87 | 37.5 | 99.7 |
YOLOv8x-cls | 224 | 79.0 | 94.6 | 232.0 | 1.01 | 57.4 | 154.8 |
-
数据准备:除了目标位置标注外,还需要给每个目标物体加上类别标签。
- 模型训练:在包含分类标签的数据集上训练 YOLOv8 模型。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-cls.yaml") # build a new model from YAML
model = YOLO("yolov8n-cls.pt") # load a pretrained model (recommended for training)
model = YOLO("yolov8n-cls.yaml").load("yolov8n-cls.pt") # build from YAML and transfer weights# Train the model
results = model.train(data="mnist160", epochs=100, imgsz=64)
- 结果评估:使用包含分类标签的验证集评估模型的分类精度。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-cls.pt") # load an official model
model = YOLO("path/to/best.pt") # load a custom model# Validate the model
metrics = model.val() # no arguments needed, dataset and settings remembered
metrics.top1 # top1 accuracy
metrics.top5 # top5 accuracy
三.实例分割
实例分割是计算机视觉中的高级任务,YOLOv8 在这一领域同样表现出色。通过分割任务,模型不仅能识别目标的位置,还能精确地勾勒出目标的边界。
Model | size (pixels) | mAPbox 50-95 | mAPmask 50-95 | Speed CPU ONNX (ms) | Speed A100 TensorRT (ms) | params (M) | FLOPs (B) |
---|---|---|---|---|---|---|---|
YOLOv8n-seg | 640 | 36.7 | 30.5 | 96.1 | 1.21 | 3.4 | 12.6 |
YOLOv8s-seg | 640 | 44.6 | 36.8 | 155.7 | 1.47 | 11.8 | 42.6 |
YOLOv8m-seg | 640 | 49.9 | 40.8 | 317.0 | 2.18 | 27.3 | 110.2 |
YOLOv8l-seg | 640 | 52.3 | 42.6 | 572.4 | 2.79 | 46.0 | 220.5 |
YOLOv8x-seg | 640 | 53.4 | 43.4 | 712.1 | 4.02 | 71.8 | 344.1 |
-
数据准备:需要准备包含目标分割掩码的数据集。
-
模型训练:在分割数据集上训练 YOLOv8 模型。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-seg.yaml") # build a new model from YAML
model = YOLO("yolov8n-seg.pt") # load a pretrained model (recommended for training)
model = YOLO("yolov8n-seg.yaml").load("yolov8n.pt") # build from YAML and transfer weights# Train the model
results = model.train(data="coco8-seg.yaml", epochs=100, imgsz=640)
- 结果评估:使用包含分割掩码的验证集评估模型的分割精度。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-seg.pt") # load an official model
model = YOLO("path/to/best.pt") # load a custom model# Validate the model
metrics = model.val() # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95(B)
metrics.box.map50 # map50(B)
metrics.box.map75 # map75(B)
metrics.box.maps # a list contains map50-95(B) of each category
metrics.seg.map # map50-95(M)
metrics.seg.map50 # map50(M)
metrics.seg.map75 # map75(M)
metrics.seg.maps # a list contains map50-95(M) of each category
四.姿势估计
姿态估计是计算机视觉中的另一重要任务,用于预测图像中人体或物体的关节点位置。YOLOv8 在这一领域也具备强大的表现力,通过姿态估计模型,可以精确地预测和标记关节点位置,适用于人体动作识别、运动分析等场景。
Model | size (pixels) | mAPpose 50-95 | mAPpose 50 | Speed CPU ONNX (ms) | Speed A100 TensorRT (ms) | params (M) | FLOPs (B) |
---|---|---|---|---|---|---|---|
YOLOv8n-pose | 640 | 50.4 | 80.1 | 131.8 | 1.18 | 3.3 | 9.2 |
YOLOv8s-pose | 640 | 60.0 | 86.2 | 233.2 | 1.42 | 11.6 | 30.2 |
YOLOv8m-pose | 640 | 65.0 | 88.8 | 456.3 | 2.00 | 26.4 | 81.0 |
YOLOv8l-pose | 640 | 67.6 | 90.0 | 784.5 | 2.59 | 44.4 | 168.6 |
YOLOv8x-pose | 640 | 69.2 | 90.2 | 1607.1 | 3.73 | 69.4 | 263.2 |
YOLOv8x-pose-p6 | 1280 | 71.6 | 91.2 | 4088.7 | 10.04 | 99.1 | 1066.4 |
-
数据准备:准备包含关节点标注的数据集,通常是标记人体关键点的位置。
- 模型训练:在姿态估计数据集上训练 YOLOv8 模型。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-pose.yaml") # build a new model from YAML
model = YOLO("yolov8n-pose.pt") # load a pretrained model (recommended for training)
model = YOLO("yolov8n-pose.yaml").load("yolov8n-pose.pt") # build from YAML and transfer weights# Train the model
results = model.train(data="coco8-pose.yaml", epochs=100, imgsz=640)
- 结果评估:使用包含关节点标注的验证集评估模型的姿态估计精度。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-pose.pt") # load an official model
model = YOLO("path/to/best.pt") # load a custom model# Validate the model
metrics = model.val() # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95
metrics.box.map50 # map50
metrics.box.map75 # map75
metrics.box.maps # a list contains map50-95 of each category
五、旋转包围框(OBB)
旋转包围框(Oriented Bounding Box, OBB)在目标检测中尤为重要,特别是在处理目标旋转角度较大的应用场景时。YOLOv8 支持 OBB 检测,能够更加精确地捕捉目标的形状和方向。
Model | size (pixels) | mAPtest 50 | Speed CPU ONNX (ms) | Speed A100 TensorRT (ms) | params (M) | FLOPs (B) |
---|---|---|---|---|---|---|
YOLOv8n-obb | 1024 | 78.0 | 204.77 | 3.57 | 3.1 | 23.3 |
YOLOv8s-obb | 1024 | 79.5 | 424.88 | 4.07 | 11.4 | 76.3 |
YOLOv8m-obb | 1024 | 80.5 | 763.48 | 7.61 | 26.4 | 208.6 |
YOLOv8l-obb | 1024 | 80.7 | 1278.42 | 11.83 | 44.5 | 433.8 |
YOLOv8x-obb | 1024 | 81.36 | 1759.10 | 13.23 | 69.5 | 676.7 |
-
数据准备:准备包含旋转包围框标注的数据集,标注每个目标的中心点、宽度、高度和旋转角度。
-
模型训练:在包含 OBB 标注的数据集上训练 YOLOv8 模型。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-obb.yaml") # build a new model from YAML
model = YOLO("yolov8n-obb.pt") # load a pretrained model (recommended for training)
model = YOLO("yolov8n-obb.yaml").load("yolov8n.pt") # build from YAML and transfer weights# Train the model
results = model.train(data="dota8.yaml", epochs=100, imgsz=640)
- 结果评估:使用包含 OBB 标注的验证集评估模型的 OBB 检测精度。
from ultralytics import YOLO# Load a model
model = YOLO("yolov8n-obb.pt") # load an official model
model = YOLO("path/to/best.pt") # load a custom model# Validate the model
metrics = model.val(data="dota8.yaml") # no arguments needed, dataset and settings remembered
metrics.box.map # map50-95(B)
metrics.box.map50 # map50(B)
metrics.box.map75 # map75(B)
metrics.box.maps # a list contains map50-95(B) of each category
六、总结
YOLOv8 通过其高效、灵活的设计,在目标识别、分类、分割、姿态估计和 OBB 检测任务中表现出色,提供了全方位的视觉解决方案。在实际应用中,合理利用 YOLOv8 的各项功能,可以大大提升计算机视觉任务的效率和效果。
如果以上内容对您有帮助,可以三连打赏订阅本专栏哦, 谢谢~