💡💡💡DCNv4更快收敛、更高速度、更高性能,完美和YOLOv13结合,助力涨点;
💡💡💡如何跟YOLOv13结合:1)加入 SPPF并与DCNv4涨点结合;
💡💡💡在NEU-DET任务中YOLOv13原始mAP50为0.742;DCNv4高效结合SPPF创新mAP50提升至0.748
博主简介
AI小怪兽,YOLO骨灰级玩家,1)YOLOv5、v7、v8、v9、v10、11、v12、v13优化创新,轻松涨点和模型轻量化;2)目标检测、语义分割、OCR、分类等技术孵化,赋能智能制造,工业项目落地经验丰富;
1.YOLOv13介绍
论文:[2506.17733] YOLOv13: Real-Time Object Detection with Hypergraph-Enhanced Adaptive Visual Perception
摘要—YOLO 系列模型因其卓越的准确性和计算效率在实时目标检测领域占据主导地位。然而,无论是 YOLO11 及更早版本的卷积架构,还是 YOLOv12 引入的基于区域的自注意力机制,都仅限于局部信息聚合和成对相关性建模,缺乏捕捉全局多对多高阶相关性的能力,这限制了在复杂场景下的检测性能。本文提出了一种准确且轻量化的 YOLOv13 目标检测器。为应对上述挑战,我们提出了一种基于超图的自适应相关性增强(HyperACE)机制,通过超图计算自适应地利用潜在的高阶相关性,克服了以往方法仅基于成对相关性建模的限制,实现了高效的全局跨位置和跨尺度特征融合与增强。随后,我们基于 HyperACE 提出了全链路聚合与分配(FullPAD)范式,通过将相关性增强特征分配到整个网络,有效实现了全网的细粒度信息流和表征协同。最后,我们提出用深度可分离卷积代替常规的大核卷积,并设计了一系列块结构,在不牺牲性能的前提下显著降低了参数量和计算复杂度。我们在广泛使用的 MS COCO 基准测试上进行了大量实验,结果表明,我们的方法在参数更少、浮点运算量更少的情况下达到了最先进性能。具体而言,我们的 YOLOv13-N 相比 YOLO11-N 提升了 3.0% 的 mAP,相比 YOLOv12-N 提升了 1.5% 的 mAP。
以往的 YOLO 系列遵循 “骨干网络 → 颈部网络 → 检测头” 的计算范式,这本质上限定了信息流的充分传输。相比之下,我们的模型通过超图自适应关联增强(HyperACE)机制,实现全链路特征聚合与分配(FullPAD),从而增强传统的 YOLO 架构。因此,我们提出的方法在整个网络中实现了细粒度的信息流和表征协同,能够改善梯度传播并显著提升检测性能。具体而言,如图 2 所示,我们的 YOLOv13 模型首先使用类似以往工作的骨干网络提取多尺度特征图 B1、B2、B3、B4、B5,但其中的大核卷积被我们提出的轻量化 DS-C3k2 模块取代。然后,与传统 YOLO 方法直接将 B3、B4 和 B5 输入颈部网络不同,我们的方法将这些特征收集并传递到提出的 HyperACE 模块中,实现跨尺度跨位置特征的高阶关联自适应建模和特征增强。随后,我们的 FullPAD 范式利用三个独立通道,将关联增强后的特征分别分配到骨干网络与颈部网络的连接处、颈部网络的内部层以及颈部网络与检测头的连接处,以优化信息流。最后,颈部网络的输出特征图被传递到检测头中,实现多尺度目标检测。
ultralytics/cfg/models/v13/yolov13.yaml
nc: 80 # number of classes scales: # model compound scaling constants, i.e. 'model=yolov13n.yaml' will call yolov13.yaml with scale 'n' # [depth, width, max_channels] n: [0.50, 0.25, 1024] # Nano s: [0.50, 0.50, 1024] # Small l: [1.00, 1.00, 512] # Large x: [1.00, 1.50, 512] # Extra Large backbone: # [from, repeats, module, args] - [-1, 1, Conv, [64, 3, 2]] # 0-P1/2 - [-1, 1, Conv, [128, 3, 2, 1, 2]] # 1-P2/4 - [-1, 2, DSC3k2, [256, False, 0.25]] - [-1, 1, Conv, [256, 3, 2, 1, 4]] # 3-P3/8 - [-1, 2, DSC3k2, [512, False, 0.25]] - [-1, 1, DSConv, [512, 3, 2]] # 5-P4/16 - [-1, 4, A2C2f, [512, True, 4]] - [-1, 1, DSConv, [1024, 3, 2]] # 7-P5/32 - [-1, 4, A2C2f, [1024, True, 1]] # 8 head: - [[4, 6, 8], 2, HyperACE, [512, 8, True, True, 0.5, 1, "both"]] - [-1, 1, nn.Upsample, [None, 2, "nearest"]] - [ 9, 1, DownsampleConv, []] - [[6, 9], 1, FullPAD_Tunnel, []] #12 - [[4, 10], 1, FullPAD_Tunnel, []] #13 - [[8, 11], 1, FullPAD_Tunnel, []] #14 - [-1, 1, nn.Upsample, [None, 2, "nearest"]] - [[-1, 12], 1, Concat, [1]] # cat backbone P4 - [-1, 2, DSC3k2, [512, True]] # 17 - [[-1, 9], 1, FullPAD_Tunnel, []] #18 - [17, 1, nn.Upsample, [None, 2, "nearest"]] - [[-1, 13], 1, Concat, [1]] # cat backbone P3 - [-1, 2, DSC3k2, [256, True]] # 21 - [10, 1, Conv, [256, 1, 1]] - [[21, 22], 1, FullPAD_Tunnel, []] #23 - [-1, 1, Conv, [256, 3, 2]] - [[-1, 18], 1, Concat, [1]] # cat head P4 - [-1, 2, DSC3k2, [512, True]] # 26 - [[-1, 9], 1, FullPAD_Tunnel, []] - [26, 1, Conv, [512, 3, 2]] - [[-1, 14], 1, Concat, [1]] # cat head P5 - [-1, 2, DSC3k2, [1024,True]] # 30 (P5/32-large) - [[-1, 11], 1, FullPAD_Tunnel, []] - [[23, 27, 31], 1, Detect, [nc]] # Detect(P3, P4, P5)
1.1 HyperACE
超图自适应相关性增强机制 HyperACE
- 超图理论借鉴与创新 :借鉴超图理论,将多尺度特征图的像素视为超图顶点,不同的是,传统超图方法依赖手工设定参数构建超边,而 HyperACE 设计了可学习的超边生成模块,能自适应地学习并构建超边,动态探索不同特征顶点间的潜在关联。
- 超图卷积操作 :在生成自适应超边后,通过超图卷积操作进行特征聚合与增强。每条超边先从其连接的所有顶点处聚合信息形成高阶特征,再将这些高阶特征传播回各个顶点,更新与增强顶点特征,从而实现高效地跨位置和跨尺度的特征融合与增强,强化不同尺度特征间的语义关联,对小目标和密集目标检测效果显著。
class HyperACE(nn.Module): """ Hypergraph-based Adaptive Correlation Enhancement (HyperACE). This is the core module of YOLOv13, designed to model both global high-order correlations and local low-order correlations. It first fuses multi-scale features, then processes them through parallel branches: two C3AH branches for high-order modeling and a lightweight DSConv-based branch for low-order feature extraction. Attributes: c1 (int): Number of input channels for the fuse module. c2 (int): Number of output channels for the entire block. n (int, optional): Number of blocks in the low-order branch. Defaults to 1. num_hyperedges (int, optional): Number of hyperedges for the C3AH branches. Defaults to 8. dsc3k (bool, optional): If True, use DSC3k in the low-order branch; otherwise, use DSBottleneck. Defaults to True. shortcut (bool, optional): Whether to use shortcuts in the low-order branch. Defaults to False. e1 (float, optional): Expansion ratio for the main hidden channels. Defaults to 0.5. e2 (float, optional): Expansion ratio within the C3AH branches. Defaults to 1. context (str, optional): Context type for C3AH branches. Defaults to "both". channel_adjust (bool, optional): Passed to FuseModule for channel configuration. Defaults to True. Methods: forward: Performs a forward pass through the HyperACE module. Examples: >>> import torch >>> model = HyperACE(c1=64, c2=256, n=1, num_hyperedges=8) >>> x_list = [torch.randn(2, 64, 64, 64), torch.randn(2, 64, 32, 32), torch.randn(2, 64, 16, 16)] >>> output = model(x_list) >>> print(output.shape) torch.Size([2, 256, 32, 32]) """ def __init__(self, c1, c2, n=1, num_hyperedges=8, dsc3k=True, shortcut=False, e1=0.5, e2=1, context="both", channel_adjust=True): super().__init__() self.c = int(c2 * e1) self.cv1 = Conv(c1, 3 * self.c, 1, 1) self.cv2 = Conv((4 + n) * self.c, c2, 1) self.m = nn.ModuleList( DSC3k(self.c, self.c, 2, shortcut, k1=3, k2=7) if dsc3k else DSBottleneck(self.c, self.c, shortcut=shortcut) for _ in range(n) ) self.fuse = FuseModule(c1, channel_adjust) self.branch1 = C3AH(self.c, self.c, e2, num_hyperedges, context) self.branch2 = C3AH(self.c, self.c, e2, num_hyperedges, context) def forward(self, X): x = self.fuse(X) y = list(self.cv1(x).chunk(3, 1)) out1 = self.branch1(y[1]) out2 = self.branch2(y[1]) y.extend(m(y[-1]) for m in self.m) y[1] = out1 y.append(out2) return self.cv2(torch.cat(y, 1))
代码位置ultralytics/nn/modules/block.py
1.2 FullPAD_Tunnel
全流程聚合 - 分发范式 FullPAD
- 多通道特征传递 :打破传统的 “骨干→颈部→头部” 单向计算范式,通过三条独立通路传递特征,即主干 - 颈部连接层、颈部内部层、颈部 - 头部连接层,将 HyperACE 聚合后的多尺度特征,通过这些 “隧道” 分发回网络的不同位置,实现细粒度信息流与全流程表征协同。
- 改善梯度传播 :该范式有效解决了梯度消失或爆炸问题,显着改善了梯度传播效率,从而提升模型整体的检测性能,使模型在复杂场景下能够更好地捕捉目标特征,提高检测的准确性和稳定性。
class FullPAD_Tunnel(nn.Module): """ A gated fusion module for the Full-Pipeline Aggregation-and-Distribution (FullPAD) paradigm. This module implements a gated residual connection used to fuse features. It takes two inputs: the original feature map and a correlation-enhanced feature map. It then computes `output = original + gate * enhanced`, where `gate` is a learnable scalar parameter that adaptively balances the contribution of the enhanced features. Methods: forward: Performs the gated fusion of two input feature maps. Examples: >>> import torch >>> model = FullPAD_Tunnel() >>> original_feature = torch.randn(2, 64, 32, 32) >>> enhanced_feature = torch.randn(2, 64, 32, 32) >>> output = model([original_feature, enhanced_feature]) >>> print(output.shape) torch.Size([2, 64, 32, 32]) """ def __init__(self): super().__init__() self.gate = nn.Parameter(torch.tensor(0.0)) def forward(self, x): out = x[0] + self.gate * x[1] return out
代码位置ultralytics/nn/modules/block.py
1.3 DSC3k2
基于深度可分离卷积的轻量化模块
- 模块创新与替代 :采用深度可分离卷积构建了 DSConv、DS-Bottleneck、DS-C3k 等模块,替代传统的大核卷积。例如使用 DS-C3k2 模块作为轻量化的骨干网络提取多尺度特征,在保持感受野的同时,大幅降低了参数量与计算量,提高了模型的计算效率。
- 性能与效率平衡 :在几乎不牺牲性能的前提下,显著减少了模型的参数量和计算复杂度,使得 YOLOv13 能够在保持较高检测精度的同时,具备更快的推理速度,适合实时目标检测应用场景,降低了模型的部署难度和资源消耗。
class DSC3k2(C2f): """ An improved C3k2 module that uses lightweight depthwise separable convolution blocks. This class redesigns C3k2 module, replacing its internal processing blocks with either DSBottleneck or DSC3k modules. Attributes: c1 (int): Number of input channels. c2 (int): Number of output channels. n (int, optional): Number of internal processing blocks to stack. Defaults to 1. dsc3k (bool, optional): If True, use DSC3k as the internal block. If False, use DSBottleneck. Defaults to False. e (float, optional): Expansion ratio for the C2f module's hidden channels. Defaults to 0.5. g (int, optional): Number of groups for grouped convolution (passed to parent C2f). Defaults to 1. shortcut (bool, optional): Whether to use shortcut connections in the internal blocks. Defaults to True. k1 (int, optional): Kernel size for the first DSConv in internal blocks. Defaults to 3. k2 (int, optional): Kernel size for the second DSConv in internal blocks. Defaults to 7. d2 (int, optional): Dilation for the second DSConv in internal blocks. Defaults to 1. Methods: forward: Performs a forward pass through the DSC3k2 module (inherited from C2f). Examples: >>> import torch >>> # Using DSBottleneck as internal block >>> model1 = DSC3k2(c1=64, c2=64, n=2, dsc3k=False) >>> x = torch.randn(2, 64, 128, 128) >>> output1 = model1(x) >>> print(f"With DSBottleneck: {output1.shape}") With DSBottleneck: torch.Size([2, 64, 128, 128]) >>> # Using DSC3k as internal block >>> model2 = DSC3k2(c1=64, c2=64, n=1, dsc3k=True) >>> output2 = model2(x) >>> print(f"With DSC3k: {output2.shape}") With DSC3k: torch.Size([2, 64, 128, 128]) """ def __init__( self, c1, c2, n=1, dsc3k=False, e=0.5, g=1, shortcut=True, k1=3, k2=7, d2=1 ): super().__init__(c1, c2, n, shortcut, g, e) if dsc3k: self.m = nn.ModuleList( DSC3k( self.c, self.c, n=2, shortcut=shortcut, g=g, e=1.0, k1=k1, k2=k2, d2=d2 ) for _ in range(n) ) else: self.m = nn.ModuleList( DSBottleneck( self.c, self.c, shortcut=shortcut, e=1.0, k1=k1, k2=k2, d2=d2 ) for _ in range(n) )
代码位置ultralytics/nn/modules/block.py
2.NEU-DET数据集介绍
NEU-DET钢材表面缺陷共有六大类,一共1800张,
类别分别为:'crazing','inclusion','patches','pitted_surface','rolled-in_scale','scratches'
标签可视化:
3.DCNv4介绍
论文: https://arxiv.org/pdf/2401.06197.pdf
摘要:我们介绍了可变形卷积v4 (DCNv4),这是一种高效的算子,专为广泛的视觉应用而设计。DCNv4通过两个关键增强解决了其前身DCNv3的局限性:去除空间聚合中的softmax归一化,增强空间聚合的动态性和表现力;优化内存访问以最小化冗余操作以提高速度。与DCNv3相比,这些改进显著加快了收敛速度,并大幅提高了处理速度,其中DCNv4的转发速度是DCNv3的三倍以上。DCNv4在各种任务中表现出卓越的性能,包括图像分类、实例和语义分割,尤其是图像生成。当在潜在扩散模型中与U-Net等生成模型集成时,DCNv4的性能优于其基线,强调了其增强生成模型的可能性。在实际应用中,将InternImage模型中的DCNv3替换为DCNv4来创建FlashInternImage,无需进一步修改即可使速度提高80%,并进一步提高性能。DCNv4在速度和效率方面的进步,以及它在不同视觉任务中的强大性能,显示了它作为未来视觉模型基础构建块的潜力。
图1所示。(a)我们以DCNv3为基准显示相对运行时间。DCNv4比DCNv3有明显的加速,并且超过了其他常见的视觉算子。(b)在相同的网络架构下,DCNv4收敛速度快于其他视觉算子,而DCNv3在初始训练阶段落后于视觉算子。
为了克服这些挑战,我们提出了可变形卷积v4 (DCNv4),这是一种创新的进步,用于优化稀疏DCN算子的实际效率。DCNv4具有更快的实现速度和改进的操作符设计,以增强其性能,我们将详细说明如下:
首先,我们对现有实现进行指令级内核分析,发现DCNv3已经是轻量级的。计算成本不到1%,而内存访问成本为99%。这促使我们重新审视运算符实现,并发现DCN转发过程中的许多内存访问是冗余的,因此可以进行优化,从而实现更快的DCNv4实现。
其次,从卷积的无界权值范围中得到启发,我们发现在DCNv3中,密集关注下的标准操作——空间聚合中的softmax归一化是不必要的,因为它不要求算子对每个位置都有专用的聚合窗口。直观地说,softmax将有界的0 ~ 1值范围放在权重上,并将限制聚合权重的表达能力。这一见解使我们消除了DCNv4中的softmax,增强了其动态特性并提高了其性能。
因此,DCNv4不仅收敛速度明显快于DCNv3,而且正向速度提高了3倍以上。这一改进使DCNv4能够充分利用其稀疏特性,成为最快的通用核心视觉算子之一。
我们进一步将InternImage中的DCNv3替换为DCNv4,创建FlashInternImage。值得注意的是,与InternImage相比,FlashInternImage在没有任何额外修改的情况下实现了50 ~ 80%的速度提升。这一增强定位FlashInternImage作为最快的现代视觉骨干网络之一,同时保持卓越的性能。在DCNv4的帮助下,FlashInternImage显著提高了ImageNet分类[10]和迁移学习设置的收敛速度,并进一步提高了下游任务的性能。
图2。(a)注意力(Attention)和(b) DCNv3使用有限的(范围从0 ~ 1)动态权值来聚合空间特征,而注意力的窗口(采样点集)是相同的,DCNv3为每个位置使用专用的窗口。(c)卷积对于聚合权值具有更灵活的无界值范围,并为每个位置使用专用滑动窗口,但窗口形状和聚合权值是与输入无关的。(d) DCNv4结合两者的优点,采用自适应聚合窗口和无界值范围的动态聚合权值。
图3。说明我们的优化。在DCNv4中,我们使用一个线程来处理同一组中的多个通道,这些通道共享采样偏移量和聚合权重。可以减少内存读取和双线性插值系数计算等工作负载,并且可以合并多个内存访问指令。
表2。具有各种下采样率的标准输入形状的运算级基准。当实现可用时报告FP32/FP16结果。在不同的输入分辨率下,我们的DCNv4可以超越所有其他常用运算符。
表3。具有各种下采样率的高分辨率输入形状的运算级基准。DCNv4作为稀疏算子表现良好,优于所有其他基线,而密集的全局关注在这种情况下速度较慢。
表4。ImageNet-1K上的图像分类性能。我们展示了FlashInternImage w/ DCNv4和它的InternImage对应版本之间的相对加速。DCNv4显着提高了速度,同时显示了最先进的性能。
3.1 DCNv4如何将入到YOLOv13
4.实验结果分析
4.1 原始结果
YOLOv13原始mAP50为0.742
YOLOv13n summary: 535 layers, 2,449,065 parameters, 0 gradients, 6.2 GFLOPs Class Images Instances Box(P R mAP50 mAP75 mAP50-95): 100%|██████████| 16/16 [00:11<00:00, 1.37it/s] all 486 1069 0.749 0.659 0.742 0.433 0.426 crazing 69 149 0.781 0.143 0.385 0.0432 0.128 inclusion 87 222 0.773 0.77 0.818 0.425 0.45 patches 92 243 0.824 0.905 0.946 0.752 0.614 pitted_surface 93 130 0.779 0.746 0.803 0.581 0.54 rolled-in_scale 81 171 0.71 0.544 0.647 0.219 0.3 scratches 90 154 0.629 0.844 0.85 0.58 0.523
4.2 DCNv4高效结合SPPF
原始mAP50为0.742提升至0.748
YOLOv13-DCNv4_SPPF summary: 552 layers, 4,467,529 parameters, 0 gradients, 7.8 GFLOPs Class Images Instances Box(P R mAP50 mAP75 mAP50-95): 100%|██████████| 16/16 [00:09<00:00, 1.65it/s] all 486 1069 0.688 0.708 0.748 0.419 0.422 crazing 69 149 0.514 0.322 0.389 0.046 0.136 inclusion 87 222 0.719 0.784 0.817 0.43 0.448 patches 92 243 0.815 0.909 0.935 0.683 0.598 pitted_surface 93 130 0.771 0.777 0.833 0.508 0.507 rolled-in_scale 81 171 0.663 0.586 0.657 0.265 0.324 scratches 90 154 0.646 0.87 0.856 0.584 0.519