Meet YOLO26: next-gen vision AI.

Link to this section知识蒸馏#

Link to this section快速入门#

通过添加 distill_model 参数,利用更强大的教师模型指导训练更小的学生模型:

示例
from ultralytics import YOLO

model = YOLO("yolo26n.pt")
model.train(data="coco8.yaml", epochs=100, distill_model="yolo26s.pt")

Link to this section什么是知识蒸馏?#

知识蒸馏 将知识从大型、高精度的教师模型传递给较小的学生模型。学生模型学习模仿教师模型的内部特征表示,通常比从零开始训练能获得更高的精度。

在以下情况下使用蒸馏:

  • 你需要一个更小、更快的模型用于部署
  • 你拥有在相同数据上训练过的高精度教师模型
  • 你想要比标准训练提供更好的精度
注意

知识蒸馏已在 detectsegmentposeobb 任务中实现。目前仅 detect 任务经过了实验性验证以确认其精度提升。

Link to this section性能#

Knowledge distillation improves student mAP across the entire YOLO26 family on COCO, with no added inference cost. The table below compares the standard YOLO26 models (baseline) against the same models trained with distillation from their recommended teacher.

模型尺寸
(像素)
mAPval
50-95

基准
mAPval
50-95

蒸馏后
mAPval
50-95 (e2e)

基准
mAPval
50-95 (e2e)

蒸馏后
YOLO26n-distill64040.941.540.140.9
YOLO26s-distill64048.649.247.848.6
YOLO26m-distill64053.153.952.553.3
YOLO26l-distill64055.056.054.455.5
YOLO26x-distill64057.557.956.957.4
  • mAPval 数值为 COCO val2017 数据集上的单模型单尺度测试结果。
    通过 yolo val detect data=coco.yaml device=0 进行复现。
  • e2e 数值使用默认的无 NMS 推理路径;非 e2e 数值使用传统的 NMS 后处理 (end2end=False)。详情请参阅 端到端检测

Link to this section前提条件#

在开始之前,请确保你满足以下要求:

  • 已训练的教师模型:一个与学生模型属于同一 YOLO 系列(例如 YOLO26)的预训练、高精度教师模型。
  • 匹配的数据集和任务:教师模型和学生模型必须使用完全相同的数据集和任务配置。
  • GPU 资源:足够的 GPU 显存 (VRAM) 以便在训练期间同时加载和运行两个模型(典型 VRAM 开销请参考 FAQ)。

Link to this section推荐的模型配对#

学生推荐教师
yolo26n.ptyolo26s.pt
yolo26s.ptyolo26m.pt
yolo26m.ptyolo26x.pt
yolo26l.ptyolo26x.pt

不支持跨系列蒸馏(例如 YOLO11 教师模型与 YOLO26 学生模型)。

Link to this section关键参数#

参数类型默认值描述
distill_modelstrNone教师模型文件的路径(例如 yolo26x.pt)。设置此参数即启用知识蒸馏。
disfloat6.0蒸馏损失权重。控制蒸馏损失对总训练损失的贡献程度。

Link to this section工作原理#

  1. 教师模型eval 模式下保持冻结,并对每个批次执行推理。
  2. 学生模型使用标准任务损失加上蒸馏指导进行训练。
  3. 特征从两个模型输入 Detect 系列头部的三个颈部层中提取。
  4. 一个投影网络(轻量级 MLP)用于对齐学生特征维度以匹配教师模型。
  5. 一个评分加权的 L2 损失通过教师的分类置信度加权,比较投影后的学生特征与教师特征。
  6. 蒸馏损失使用 dis 权重与标准损失相结合。
flowchart TD
    A[Input Image Batch] --> T[Teacher Model<br/>frozen, eval mode]
    A --> S[Student Model<br/>trainable]

    T --> |Detect head inputs| TF[Teacher Features]
    S --> |Detect head inputs| SF[Student Features]

    SF --> P[1×1 Conv Projector<br/>with ReLU]
    P --> AF[Aligned Student Features]

    TF --> SW[Score-weighted L2 Loss]
    AF --> SW

    S --> D[Detection Head]
    D --> DL[box_loss + cls_loss + dfl_loss]

    SW --> |× dis| DIS[distillation loss]
    DL --> TOTAL[Total Loss]
    DIS --> TOTAL

    TOTAL --> BP[Backpropagate<br/>Student + Projector only]

Link to this section任务支持#

蒸馏实现从输入模型 Detect 系列头部的三个颈部层提取特征。由于 segmentposeobb 头部继承自相同的 Detect 架构,因此蒸馏在技术上也兼容这些任务。

警告

目前仅 detect 经过了实验性基准测试和验证。你可以对 segmentposeobb 运行蒸馏,但这些任务的精度提升尚未得到验证。

其他任务的知识蒸馏
from ultralytics import YOLO

# Segment
model = YOLO("yolo26n-seg.pt")
model.train(data="coco8-seg.yaml", epochs=100, distill_model="yolo26s-seg.pt")

# Pose
model = YOLO("yolo26n-pose.pt")
model.train(data="coco8-pose.yaml", epochs=100, distill_model="yolo26s-pose.pt")

# OBB
model = YOLO("yolo26n-obb.pt")
model.train(data="dota8.yaml", epochs=100, distill_model="yolo26s-obb.pt")

Link to this section训练#

Link to this section基础训练#

带蒸馏的训练与标准训练相同。提供 distill_model 路径即可启用:

知识蒸馏训练
from ultralytics import YOLO

# Load a student model
student = YOLO("yolo26m.pt")

# Train with knowledge distillation from a larger teacher model
results = student.train(data="coco8.yaml", epochs=100, distill_model="yolo26x.pt")

Link to this section调整蒸馏损失权重#

dis 参数(默认:6.0)控制蒸馏损失的贡献:

自定义蒸馏权重
from ultralytics import YOLO

student = YOLO("yolo26n.pt")
results = student.train(data="coco8.yaml", epochs=100, distill_model="yolo26s.pt", dis=10.0)

Link to this section恢复蒸馏训练#

蒸馏训练支持从检查点恢复。教师模型会自动从 distill_model 路径重新构建:

恢复蒸馏训练
from ultralytics import YOLO

student = YOLO("runs/detect/train/weights/last.pt")
results = student.train(resume=True)

Link to this section训练输出#

当启用蒸馏时,训练日志中会出现额外的 dis_loss 列:

      Epoch    GPU_mem   box_loss   cls_loss   dfl_loss   dis_loss  Instances       Size
      1/80      46.2G      1.566      5.404    0.003249      6.658        231        640

导出的模型仅包含学生权重——文件大小和推理速度与正常训练的学生模型一致。

Link to this section常见问题解答#

Link to this section为什么我的蒸馏损失没有下降?#

  • 验证教师模型和学生模型是否来自同一 YOLO 代际
  • 确认 distill_model 路径正确且文件可加载。
  • 如果损失值非常小,尝试增加 dis
  • 确保教师模型是在相同数据集上训练的。

Link to this section蒸馏与标准训练有何不同?#

添加 distill_model 参数——其余操作完全相同。训练期间会计算额外的蒸馏损失,但保存的模型是标准的 YOLO 模型,没有任何额外开销。

Link to this section知识蒸馏会减慢训练速度吗?#

是的。预计训练速度会慢 1.2-1.5 倍,GPU 显存占用增加约 1.1 倍,因为教师模型会在每个批次上运行推理。教师模型在不计算梯度的 eval 模式下运行,开销可控。使用 amp=True 可以减少影响。

Link to this section支持哪些任务和模型?#

知识蒸馏适用于 detectsegmentposeobb 任务,因为它提取输入 Detect 系列头部的三个颈部层的特征。不支持 classifysemantic 任务。

detect 任务经过了实验性验证以确认精度提升。Segment、pose 和 obb 技术上兼容,但尚未进行基准测试。

教师和学生必须属于同一 YOLO 系列(例如 YOLOv8、YOLO11 或 YOLO26)。不支持跨系列蒸馏(例如 YOLO11 教师模型与 YOLO26 学生模型)。

贡献者

评论