YOLOv8 项目地址:https://github.com/ultralytics/ultralytics
YOLOv8
Ultralytics YOLOv8
是由 Ultralytics
开发的一个前沿的 SOTA
模型。它在以前成功的 YOLO
版本基础上,引入了新的功能和改进,进一步提升了其性能和灵活性。YOLOv8
基于快速、准确和易于使用的设计理念,使其成为广泛的目标检测、图像分割和图像分类任务的绝佳选择。
网络结构上其实和YOLOv5
差别不大,YOLOv8的详细原理就不过多解析了,这里我们只介绍将YOLOv8
中的C2f
模块添加到YOLOv5/v7
中的方法。
代码修改方式
将如下代码添加到common.py
中:
class v8_Bottleneck(nn.Module):
# Standard bottleneck
def __init__(self, c1, c2, shortcut=True, g=1, k=(3, 3), e=0.5): # ch_in, ch_out, shortcut, groups, kernels, expand
super().__init__()
c_ = int(c2 * e) # hidden channels
self.cv1 = Conv(c1, c_, k[0], 1)
self.cv2 = Conv(c_, c2, k[1], 1, g=g)
self.add = shortcut and c1 == c2
def forward(self, x):
return x + self.cv2(self.cv1(x)) if self.add else self.cv2(self.cv1(x))
class C2f(nn.Module):
# CSP Bottleneck with 2 convolutions
def __init__(self, c1, c2, n=1, shortcut=False, g=1, e=0.5): # ch_in, ch_out, number, shortcut, groups, expansion
super().__init__()
self.c = int(c2 * e) # hidden channels
self.cv1 = Conv(c1, 2 * self.c, 1, 1)
self.cv2 = Conv((2 + n) * self.c, c2, 1) # optional act=FReLU(c2)
self.m = nn.ModuleList(v8_Bottleneck(self.c, self.c, shortcut, g, k=((3, 3), (3, 3)), e=1.0) for _ in range(n))
def forward(self, x):
y = list(self.cv1(x).split((self.c, self.c), 1))
y.extend(m(y[-1]) for m in self.m)
return self.cv2(torch.cat(y, 1))
在yolo.py
中添加C2f
修改配置文件yolov8s.yaml
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
# Parameters
nc: 80 # number of classes
depth_multiple: 0.33 # model depth multiple
width_multiple: 0.50 # layer channel multiple
anchors:
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32
# YOLOv5 v6.0 backbone
backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 3, 2 ]], # 0-P1/2
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C2f, [128, True]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 6, C2f, [256, True]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 6, C2f, [512, True]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 3, C2f, [1024, True]],
[-1, 1, SPPF, [1024]]
]
# YOLOv5 v6.0 head
head:
[[-1, 1, Conv, [512, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 6], 1, Concat, [1]], # cat backbone P4
[-1, 3, C3, [512, False]], # 13
[-1, 1, Conv, [256, 1, 1]],
[-1, 1, nn.Upsample, [None, 2, 'nearest']],
[[-1, 4], 1, Concat, [1]], # cat backbone P3
[-1, 3, C3, [256, False]], # 17 (P3/8-small)
[-1, 1, Conv, [256, 3, 2]],
[[-1, 14], 1, Concat, [1]], # cat head P4
[-1, 3, C3, [512, False]], # 20 (P4/16-medium)
[-1, 1, Conv, [512, 3, 2]],
[[-1, 10], 1, Concat, [1]], # cat head P5
[-1, 3, C3, [1024, False]], # 23 (P5/32-large)
[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
]
本人更多YOLOv5实战内容导航🍀🌟🚀
-
手把手带你调参Yolo v5 (v6.2)(推理)🌟强烈推荐
-
手把手带你调参Yolo v5 (v6.2)(训练)🚀
-
手把手带你调参Yolo v5 (v6.2)(验证)
-
如何快速使用自己的数据集训练Yolov5模型
-
手把手带你Yolov5 (v6.2)添加注意力机制(一)(并附上30多种顶会Attention原理图)🌟强烈推荐🍀新增8种
-
手把手带你Yolov5 (v6.2)添加注意力机制(二)(在C3模块中加入注意力机制)
-
Yolov5如何更换激活函数?
-
Yolov5如何更换BiFPN?
-
Yolov5 (v6.2)数据增强方式解析
-
Yolov5更换上采样方式( 最近邻 / 双线性 / 双立方 / 三线性 / 转置卷积)
-
Yolov5如何更换EIOU / alpha IOU / SIoU?
-
Yolov5更换主干网络之《旷视轻量化卷积神经网络ShuffleNetv2》
-
YOLOv5应用轻量级通用上采样算子CARAFE
-
空间金字塔池化改进 SPP / SPPF / SimSPPF / ASPP / RFB / SPPCSPC / SPPFCSPC🚀
-
用于低分辨率图像和小物体的模块SPD-Conv
-
GSConv+Slim-neck 减轻模型的复杂度同时提升精度🍀
-
头部解耦 | 将YOLOX解耦头添加到YOLOv5 | 涨点杀器🍀
-
Stand-Alone Self-Attention | 搭建纯注意力FPN+PAN结构
-
YOLOv5模型剪枝实战🚀
-
YOLOv5知识蒸馏实战🚀
-
YOLOv7知识蒸馏实战🚀
-
改进YOLOv5 | 引入密集连接卷积网络DenseNet思想 | 搭建密集连接模块
-
YOLOv5更换骨干网络之 PP-LCNet
-
YOLOv5更换骨干网络之 EfficientNet-B0
-
YOLOv5更换骨干网络之 MobileNet V3
-
YOLOv5更换骨干网络之 GhostNet
-
YOLOv5 引入 最新 BiFusion Neck
-
YOLOv5/v7 引入 RepVGG 重参数化模块 🍀