Meet YOLO26: next-gen vision AI.

Link to this sectionYOLO 架构详解:从 YOLOv3 到 YOLO26#

每个 Ultralytics YOLO 模型均由三个阶段构建:提取特征的 backbone(主干)、跨尺度融合特征的 neck(颈部)以及预测边界框和类别的 head(检测头)。本指南记录了构成每个阶段的模块,以及它们如何从 YOLOv3 演变为 YOLO26,并追踪了每个组件在 ultralytics/cfg/models/ 下配置文件中的定义及其在 ultralytics/nn/modules/ 中的模块类。

每个模型均在 YAML 文件中以层级的有序列表进行声明式定义,其中每一层都遵循 [from, repeats, module, args] 格式:输入来源层、模块重复次数、层类(ConvC3k2SPPFDetect 等)及其构造函数参数。Model YAML Configuration Guide 记录了此格式——包括 repeatsargs 如何随模型变体的深度和宽度乘数进行缩放——以及完整的模块解析系统。本指南侧重于模块本身及其在不同版本间的变化。

Link to this section三个阶段#

每个 Ultralytics YOLO 模型都将图像通过三个顺序阶段进行路由,每个阶段都有明确的任务:

阶段任务输出
Backbone在多个分辨率下从输入图像中提取特征步长为 8、16 和 32 的特征图(P3、P4、P5)
Neck跨尺度融合特征,使小目标和大目标都能拥有上下文信息多尺度融合特征图
Head从融合后的特征中预测边界框和类别分数每个锚点的检测结果

基础单元是 Conv 块(定义于 conv.py):按顺序应用 2D 卷积、batch normalizationSiLU 激活。下方所有较大的模块均由 Conv 块组合而成。

Link to this section架构图#

Each version keeps the same backbone → neck → head skeleton and changes specific stages. The tabs below show the per-version structure: the backbone and neck stages follow the configs in ultralytics/cfg/models/, while the YOLOv3 and YOLOv5 heads are drawn in their original anchor-based form rather than the anchor-free u-variant head their package configs actually ship. Stepping through the tabs shows what each generation added. In short, the progression is: YOLOv3 is an FPN-only, anchor-based detector; YOLOv5 adds the bottom-up PAN path and SPPF; YOLOv8 switches to the C2f block with an anchor-free, DFL head; YOLO11 inserts C2PSA attention and the C3k2 block; and YOLO26 adds an SPPF residual and makes the head NMS-free and DFL-free. Node colors follow the documentation diagram convention: green input, blue backbone, slate spatial pooling and attention, orange neck, purple head and output.

flowchart TD
    IN[Input 640x640]:::start --> ST[Conv stem<br/>5x stride-2 down to P1-P5]:::proc
    ST --> BB[Darknet-53 backbone<br/>stacked Bottleneck]:::proc
    BB --> FPN[Neck FPN only<br/>top-down Upsample + Concat]:::decide
    FPN --> HD[Detect head<br/>3 scales, anchor-based]:::out
    HD --> O[Predictions + NMS]:::out
    classDef start fill:#4CAF50,color:#fff
    classDef proc fill:#2196F3,color:#fff
    classDef decide fill:#FF9800,color:#fff
    classDef out fill:#9C27B0,color:#fff

The YOLOv3 and YOLOv5 diagrams show the original anchor-based head. The ultralytics package ships the anchor-free YOLOv3u and YOLOv5u configs — the same Darknet-53 and C3 backbones with YOLOv8's Detect head — described under Detection Head.

Link to this sectionBackbone 块:Bottleneck → C3 → C2f → C3k2#

Backbone 在步长为 2 的 Conv 下采样层之间堆叠了重复的 CSP(跨阶段局部)块。该重复块是各版本间变化最大的部分。下方所有块均位于 block.py 中;c1/c2 分别为输入/输出通道,c = 0.5 * c2 为隐藏宽度。

Link to this sectionBottleneck (YOLOv3)#

基础单元是 Bottleneck:两个 Conv 层(默认内核 (3, 3)),在 shortcut=Truec1 == c2 时带有可选的残差相加。YOLOv3Darknet-53 backbone 直接堆叠了这些单元,无需 CSP 分割,并在三个尺度(步长 8、16、32)上进行检测。

Link to this sectionC3 (YOLOv5)#

YOLOv5C3 将输入通过两个 1x1 卷积进行分割:cv1 输入 n 个顺序的 Bottleneck 块(内核 (1, 1) 后接 (3, 3)),cv2 则绕过它们。两条路径被连接并由第三个 1x1 Conv 融合:

def forward(self, x):
    # C3: bottleneck path m(cv1(x)) concatenated with bypass cv2(x), then fused by cv3
    return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), 1))

只有最终的 bottleneck 输出到达融合 conv,因此 cv3 接收到 2 个特征图。

Link to this sectionC2f (YOLOv8)#

YOLOv8C2f(“带有 2 个卷积的 CSP Bottleneck,速度更快”)改变了到达融合 conv 的特征:

  1. cv1 = Conv(c1, 2 * c, 1),然后通过 chunk(2) 将输出分割为两个 c 通道的张量。
  2. nBottleneck(c, c) 块(内核 (3, 3)(3, 3))顺序运行,每个块接收前一个块的输出。
  3. 所有 n + 2 个中间张量被连接并由 cv2 = Conv((2 + n) * c, c2, 1) 融合。

C3 将 2 个特征图传入其融合 conv 不同,C2f 传入 n + 2 个——每个中间的 bottleneck 输出都会被重用。

Link to this sectionC3k2 (YOLO11 和 YOLO26)#

YOLO11YOLO26 使用 C3k2,这是 C2f 的子类,交换了重复单元。根据构造函数标志,每个 n 块变为:

  • 普通的 Bottleneck(默认,c3k=False),
  • 一个 C3k 块(c3k=True)——一种具有可配置内核大小的 C3 变体,或者
  • 一个 Bottleneck + PSABlock 对(attn=True)。

第二个 YAML 参数设置 c3k;例如 [-1, 2, C3k2, [512, True]] 构建了一个在 512 输出通道处的 C3k2 模块,其内部块为 C3k(因为 c3k=True)。对于 CSP 模块,repeats 字段(此处为 2,在通过变体的深度乘数缩放之前)成为块的内部重复计数,而不是堆叠独立的模块。

Link to this section空间池化:SPP → SPPF#

At the end of the backbone, a spatial-pyramid-pooling block widens the receptive field. YOLOv5 replaced the original multi-kernel SPP with SPPF (Spatial Pyramid Pooling - Fast): a single MaxPool2d(kernel_size=5, stride=1, padding=2) applied n = 3 times in sequence, with the input and all three pooled outputs concatenated and fused by a 1x1 Conv. This is mathematically equivalent to SPP(k=(5, 9, 13)) but cheaper, because the chained 5x5 pools cover the larger kernels' receptive fields.

YOLO26 传递一个快捷方式标志(SPPF, [1024, 5, 3, True]);由于在最深层 c1 == c2 == 1024SPPF 增加了一个残差连接(return y + x)。

Link to this section空间注意力:C2PSA (YOLO11+)#

YOLO11 added C2PSA after SPPF. It is a CSP block whose active branch is a stack of n PSABlock (Position-Sensitive Attention) modules: cv1 = Conv(c1, 2 * c, 1) splits the features, one half passes through the PSABlock stack, and cv2 = Conv(2 * c, c1, 1) fuses the concatenation. Each PSABlock applies multi-head attention followed by a two-layer feed-forward network (Conv(c, 2 * c, 1)Conv(2 * c, c, 1)), each with a residual connection. YOLO26 keeps the same C3k2 + C2PSA backbone.

Link to this sectionNeck:FPN + PAN#

Neck 通过自上而下的特征金字塔网络(FPN)和随后的自下而上的路径聚合网络(PAN)融合 backbone 的 P3/P4/P5 特征图。在 YAML 的 head 部分,FPN 是 nn.Upsample + Concat(将语义信息向下传递到更高的分辨率),PAN 是步长为 2 的 Conv + Concat(将定位信息向上带回):

# YOLO11 head (FPN top-down, then PAN bottom-up)
- [-1, 1, nn.Upsample, [None, 2, "nearest"]]
- [[-1, 6], 1, Concat, [1]] # cat backbone P4
- [-1, 2, C3k2, [512, False]] # 13
# ... second upsample + concat to P3 ...
- [-1, 1, Conv, [256, 3, 2]]
- [[-1, 13], 1, Concat, [1]] # cat head P4 (PAN)
- [-1, 2, C3k2, [512, False]] # 19

Neck 重用了其一代的 backbone 块——YOLOv5 中的 C3,YOLOv8 中的 C2f,YOLO11 和 YOLO26 中的 C3k2——因此每个融合点都运行与 backbone 相同的模块。三个融合输出输入到 head。YOLOv3 是个例外:其 neck 仅是自上而下的 FPN(其 YAML head 没有步长为 2 的下采样),而没有 YOLOv5 引入的自下而上的 PAN 路径。

Link to this section检测头:基于锚点 → 无锚点 → 无 NMS#

Head 将三个融合的特征图转换为 detection task 的预测。其设计在各个版本间发生了变化,从基于锚点到无锚点,再到无 NMS。

Link to this section无锚点,解耦的 Detect#

The original YOLOv3 and YOLOv5 used an anchor-based, coupled head: predefined anchor boxes and a shared branch for box and class predictions. The standalone ultralytics/yolov3 and ultralytics/yolov5 repositories keep that anchor-based design. The main ultralytics package instead ships the anchor-free YOLOv3u and YOLOv5u variants — the same Darknet-53 and C3 backbones with YOLOv8's anchor-free Detect head — and the yolov3.yaml and yolov5.yaml configs documented here are these u variants, not the historical design.

Detect head (head.py) 是无锚点且解耦的:在每个金字塔级别,它运行两个并行分支,并直接在网格点上进行预测,而不是针对锚框。

  • 框分支 (cv2): Conv(x, c2, 3)Conv(c2, c2, 3)Conv2d(c2, 4 * reg_max, 1)
  • 类别分支 (cv3): 在 YOLO11 和 YOLO26 中,两个深度可分离块(DWConv + 1x1 Conv) → Conv2d(c3, nc, 1);YOLOv8 使用传统变体,两个 3x3 Conv 层 → Conv2d(c3, nc, 1)

因此,每个锚点发射 no = nc + 4 * reg_max 个输出。移除预定义的锚点减少了需要调整的超参数中的锚框大小和宽高比。

Link to this section分布焦点损失 (DFL)#

YOLOv8 和 YOLO11 将 4 个框坐标中的每一个回归为 reg_max = 16 个箱(bin)上的分布,而不是单个标量(来自 Generalized Focal Loss 的积分形式)。DFL 模块将 4 * reg_max 框通道重塑为 (4, reg_max),在 reg_max 箱上应用 softmax,并取期望的箱索引——每个箱索引由其 softmax 概率加权,然后求和——作为预测坐标。这实现为一个固定的 1x1 卷积,其权重为箱索引 arange(reg_max),因此加权和是一个单一的点积。

Link to this sectionYOLO26:无 NMS,无 DFL#

YOLO26 设置了两个 head 直接读取的 YAML 参数:

  • end2end: TrueDetect 将其分支深度复制到一对一的 head (one2one_cv2/one2one_cv3) 中,为每个对象产生单个预测,消除了 Non-Maximum Suppression (NMS) 后处理步骤。有关导出和迁移详情,请参阅 End-to-End Detection guide
  • reg_max: 1 — 有一个箱时,self.dfl 变为 nn.Identity()no = nc + 4;head 直接回归坐标,导出的 ONNX 图中不会出现 DFL 操作。

在其五种模型大小 (n/s/m/l/x) 中,YOLO26 在 COCO 上达到 40.9-57.5 mAP,T4 TensorRT 延迟为 1.7-11.8 ms,详见 YOLO26 paper

Link to this section版本总结#

版本Backbone 块空间池化注意力检测头DFL
YOLOv3Darknet-53 (Bottleneck)基础配置中没有原始:基于锚点;u 变体:无锚点无 / 有 (u)
YOLOv5C3 (CSP)SPPF原始:基于锚点;u 变体:无锚点无 / 有 (u)
YOLOv8C2fSPPF无锚点,解耦有 (reg_max=16)
YOLO11C3k2SPPFC2PSA无锚点,解耦有 (reg_max=16)
YOLO26C3k2SPPF + 快捷方式C2PSA无锚点,无 NMS (end2end)已移除 (reg_max=1)

有关各模型详情、性能表和使用示例,请参见 YOLOv3YOLOv5YOLOv8YOLO11YOLO26 的独立页面。

Link to this section亲自检查架构#

model.info() 方法打印层、参数和 FLOPs 摘要,解析后的模块列表可在 model.model.model 上获取。

检查 YOLO 模型的架构
from ultralytics import YOLO

# Load a pretrained model
model = YOLO("yolo11n.pt")

# Fuse Conv + BatchNorm layers so counts match the published specs
model.fuse()

# Print a summary: layers, parameters, gradients, GFLOPs
model.info()

# Inspect the detection head (the last module in the network)
head = model.model.model[-1]
print(type(head).__name__, "| reg_max:", head.reg_max, "| end2end:", head.end2end)

跨三代运行该片段可数值化地显示变化。这些是来自 ultralytics 包的真实融合模型输出,匹配每个 model page 上发布的参数和 FLOPs 计数:

模型层数参数量GFLOPsreg_maxend2endDFL 层
YOLOv8n723,151,9048.716FalseDFL
YOLO11n1002,616,2486.516FalseDFL
YOLO26n1222,408,9325.41TrueIdentity

YOLO26n 报告 reg_max=1end2end=True 和一个 Identity DFL 层——这是其无 NMS、无 DFL head 的架构特征。

融合与未融合计数

参数和 FLOPs 值是针对融合(fused)模型(model.fuse())报告的,该操作会合并每个 Conv 及其 batch normalization 层。这与已发布的规格相符;在融合之前,刚加载的检查点(checkpoint)会报告略高的计数值。

Link to this section结论#

在不同版本中,YOLO 架构每次更新一个阶段:骨干网络(backbone)从 Darknet-53 演进为基于 CSP 的 C3C2fC3k2 块以及 C2PSA 注意力机制;颈部(neck)保持 FPN + PAN 结构,同时 SPP 变为 SPPF;头部(head)则从基于锚框(anchor-based)转向无锚框(anchor-free),最终演进为 YOLO26 的无 NMS、无 DFL 的端到端设计。

要定义自定义架构,请参阅 Model YAML Configuration Guide,或在 model pages 上对比不同模型。如有疑问,请在 GitHubDiscord 上联系我们。

Link to this section常见问题解答#

Link to this sectionYOLO 架构的三个阶段是什么?#

YOLO 模型具有一个骨干网络(backbone),用于在 8、16 和 32 的步长(strides)下提取图像特征;一个颈部(neck),通过 FPN 和 PAN 在不同尺度上融合这些特征;以及一个头部(head),用于预测边界框(bounding boxes)和类别得分。从 YOLOv3 到 YOLO26,每一款 Ultralytics YOLO 模型都遵循这种三阶段设计。

Link to this sectionC2f 和 C3k2 块之间有什么区别?#

C2f (YOLOv8) is a CSP block that concatenates the outputs of every internal Bottleneckn + 2 feature maps — before its fusion convolution, where the older C3 passes only 2. C3k2 (YOLO11 and YOLO26) is a subclass of C2f that can replace each Bottleneck with a C3k block (a C3 variant with a configurable kernel size) when its c3k flag is set. Both are defined in block.py.

Link to this section从 YOLOv8 到 YOLO11,架构发生了什么变化?#

YOLO11 makes three structural changes to YOLOv8: it replaces the C2f backbone and neck block with C3k2, inserts a C2PSA self-attention block after SPPF, and switches the head's classification branch to lighter depthwise-separable convolutions. Both keep the same anchor-free, decoupled Detect head with reg_max=16 DFL regression, so the changes lower parameter and FLOPs counts while raising accuracy rather than redesigning the detection interface.

Link to this sectionYOLO 是无锚框(anchor-free)的吗?#

现代 Ultralytics YOLO 模型均采用无锚框设计。YOLOv8、YOLO11 和 YOLO26 使用无锚框、解耦的 Detect 头部,为框回归和分类提供独立的分支。原始的 YOLOv3 和 YOLOv5 是基于锚框的,但 Ultralytics 将它们作为 YOLOv3uYOLOv5u 变体发布,其配置使用了与 YOLOv8 相同的无锚框头部。

Link to this sectionYOLO26 是否移除了 NMS?#

是的——YOLO26 设置了 end2end=True,这使得 Detect 拥有一个“一对一”头部,每个目标仅生成一个预测结果,从而移除了早期模型所需的非极大值抑制(NMS)后处理步骤。详细信息请参阅 End-to-End Detection guide

Link to this section什么是分布焦点损失(DFL),为什么 YOLO26 要移除它?#

DFL 将每个框坐标回归为 reg_max 个箱(在 YOLOv8 和 YOLO11 中默认为 16)上的 softmax 分布,并取期望值作为坐标,而不是直接预测单个标量。YOLO26 将 reg_max=1,因此 DFL 层变为恒等运算,头部直接回归坐标,并且在导出的 ONNX 或 TensorRT 图中不再出现 DFL 操作。

Link to this section如何查看特定 YOLO 模型的架构?#

在 Python 中加载模型并调用 model.info() 以获取层、参数和 GFLOPs 的摘要。解析后的层位于 model.model.model 中——例如,model.model.model[-1]Detect 头部,它公开了诸如 reg_maxend2end 等属性。完整架构定义在模型的 YAML 配置文件 中。

贡献者

评论