Meituan YOLOv6
概述#
美团 YOLOv6 于 2022 年发布,是一种目标检测模型,在速度和精度之间实现了良好平衡,因此成为实时应用的热门选择。该模型在架构和训练方案上引入了多项显著改进,包括实现双向拼接(BiC)模块、辅助锚框训练(AAT)策略,以及改进的骨干网络和颈部结构,从而在COCO 数据集上实现高精度。
YOLOv6 概览。模型架构图展示了经过重新设计的网络组件和训练策略,这些改进带来了显著的性能提升。(a) YOLOv6 的颈部(图中展示 N 和 S)。请注意,对于 M/L,RepBlocks 替换为 CSPStackRep。(b) BiC 模块的结构。(c) SimCSPSPPF 模块。(来源。
主要功能#
- 双向拼接 (BiC) 模块:YOLOv6 在检测器颈部引入了 BiC 模块,增强定位信号,并在速度几乎不受影响的情况下提升性能。
- 辅助锚框训练(AAT)策略: AAT 结合了基于锚框和无锚框范式的优点,同时不影响推理效率。
- 增强的主干网络和颈部设计:通过加深 YOLOv6,并在主干网络和颈部各增加一个阶段,该模型在发布时以高分辨率输入在 COCO 数据集上取得了出色表现。
- 自蒸馏策略: 实现了一种新的自蒸馏策略,以提升较小型 YOLOv6 模型的性能;该策略在训练期间增强辅助回归分支,并在推理时将其移除,以避免速度明显下降。
性能指标#
YOLOv6 提供了不同规模的多种预训练模型:
- YOLOv6-N:在 COCO val2017 上 AP 为 37.5%,使用 NVIDIA T4 GPU 时速度为 1187 FPS。
- YOLOv6-S:AP 为 45.0%,速度为 484 FPS。
- YOLOv6-M:AP 为 50.0%,速度为 226 FPS。
- YOLOv6-L:AP 为 52.8%,速度为 116 FPS。
- YOLOv6-L6:实时场景下实现先进的准确率。
YOLOv6 还提供不同数值精度的量化模型,以及针对移动平台优化的模型。
使用示例#
YOLOv6 *.yaml 文件可传递给 YOLO() 类,以便在 Python 中构建对应模型:
from ultralytics import YOLO
# 从头开始构建 YOLOv6n 模型
model = YOLO("yolov6n.yaml")
# 显示模型信息(可选)
model.info()
# 使用 COCO8 示例数据集训练模型 100 个 epoch
results = model.train(data="coco8.yaml", epochs=100, imgsz=640)
# 使用 YOLOv6n 模型对“bus.jpg”图像运行推理
results = model("path/to/bus.jpg")支持的任务和模式#
YOLOv6 系列提供多种模型,每种模型都针对目标检测进行了优化,可满足不同的计算预算和精度要求。
| 模型 | 文件名 | 任务 | 训练 | 验证 | 推理 | 导出 |
|---|---|---|---|---|---|---|
| YOLOv6-N | yolov6n.yaml | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv6-S | yolov6s.yaml | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv6-M | yolov6m.yaml | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv6-L | yolov6l.yaml | 目标检测 | ✅ | ✅ | ✅ | ✅ |
| YOLOv6-X | yolov6x.yaml | 目标检测 | ✅ | ✅ | ✅ | ✅ |
此表总结了 YOLOv6 各模型变体及其对训练、验证、推理和导出模式的支持情况。Ultralytics 仅提供 YOLOv6 模型 YAML 文件,因此模型需要从头开始训练。
引用与致谢#
我们谨此感谢作者在实时目标检测领域做出的重要贡献:
@misc{li2023yolov6,
title={YOLOv6 v3.0: A Full-Scale Reloading},
author={Chuyi Li and Lulu Li and Yifei Geng and Hongliang Jiang and Meng Cheng and Bo Zhang and Zaidan Ke and Xiaoming Xu and Xiangxiang Chu},
year={2023},
eprint={2301.05586},
archivePrefix={arXiv},
primaryClass={cs.CV}
}YOLOv6 原始论文可在 arXiv 上查阅。作者公开了他们的研究成果,代码库可在 GitHub 上访问。我们感谢他们为推动该领域发展所付出的努力,以及让更广泛的社区能够使用其成果。
常见问题#
Meituan YOLOv6 于 2022 年发布,是一款兼顾速度和准确率、专为实时应用设计的目标检测器。它具有多项重要的架构改进,例如双向拼接 (BiC) 模块和锚点辅助训练 (AAT) 策略。这些创新在速度几乎不受影响的情况下显著提升了性能,使 YOLOv6 成为目标检测任务的有力选择。
你可以使用简单的 Python 或 CLI 命令,通过 Ultralytics 训练 YOLOv6 模型。例如:
示例from ultralytics import YOLO # 从头开始构建 YOLOv6n 模型 model = YOLO("yolov6n.yaml") # 使用 COCO8 示例数据集训练模型 100 个 epoch results = model.train(data="coco8.yaml", epochs=100, imgsz=640)如需了解更多信息,请访问训练页面。
YOLOv6 提供多个版本,每个版本都针对不同的性能需求进行了优化:
- YOLOv6-N:AP 为 37.5%,速度为 1187 FPS
- YOLOv6-S:AP 为 45.0%,速度为 484 FPS
- YOLOv6-M:AP 为 50.0%,速度为 226 FPS
- YOLOv6-L:AP 为 52.8%,速度为 116 FPS
- YOLOv6-L6:在实时场景中实现先进的准确率
这些模型使用 NVIDIA T4 GPU 在 COCO 数据集上进行评估。如需了解更多性能指标,请参阅性能指标部分。
YOLOv6 中的锚点辅助训练 (AAT) 结合了基于锚点和无锚点方法的特点,在不影响推理效率的情况下增强模型的检测能力。该策略在训练期间利用锚点来改进边界框预测,使 YOLOv6 能够有效应对各种目标检测任务。
YOLOv6 支持训练、验证、推理和导出模式。
评论14
提出问题、分享结果,或帮助其他人。
AkaashSamson
Hey, So I have actually trained my YOLOv6 model with the original repo, now I have a .pt file. using this file is there any way of getting my model in ultralytics format. mainly I want to run the ultralytics validation on my model as the original repo eval.py doesn't provide sufficient metrics.
Glenn JocherUltralyticsDirect conversion of Meituan YOLOv6 .pt checkpoints to Ultralytics format isn’t supported; to use Ultralytics metrics, either train/fine-tune the matching yolov6*.yaml in Ultralytics and run validation, or export your Meituan model’s detections to COCO JSON and compute P/R via the COCO API; the metrics Ultralytics reports are outlined in the Val mode docs at Ultralytics validation.
tino926(已编辑)
I want to replicate your training accuracy of the YOLOv6-N model. Is this the correct command:
yolo train model=yolov6n.yaml data=coco.yaml epochs=400 optimizer=SGD cos_lr=True lr0=0.02? According to YOLOv6's repo https://github.com/meituan/YOLOv6/blob/main/docs/Train_coco_data.md, they have to use anchor-aid and distilling techniques to achieve this accuracy. But I can't find the corresponding parameters in ultralytics'.
Glenn JocherUltralytics@tino926 to achieve the training accuracy of the YOLOv6-N model as described in the YOLOv6 repository, you would indeed use the anchor-aided training (AAT) and self-distillation strategies, which are not explicitly parameterized in the Ultralytics YOLO interface. Ensure you are using the latest version and check the YOLOv6 documentation for any updates on incorporating these strategies. For precise replication, consider following the original YOLOv6 GitHub instructions alongside Ultralytics for any additional settings or configurations.
tino926
@glenn-jocher, thanks for your response.
I apologize if I misunderstood your explanation, as I am not a native English speaker. Could you please clarify if the phrase "which are not explicitly parameterized in the Ultralytics YOLO interface" means that AAT and self-distillation cannot currently be implemented solely through the Ultralytics YOLO interface? Therefore I should manually add anchor branches and implement distillation with additional code?
Glenn JocherUltralyticsThank you for your question. Yes, that's correct. The current Ultralytics YOLO interface does not explicitly support anchor-aided training (AAT) and self-distillation, so you would need to implement these strategies manually by modifying the code to include anchor branches and self-distillation techniques. If you need further guidance on implementing these, referring to the original YOLOv6 repository might be helpful.
kadirnar
Does ultralytics library support yolov6 model?
ModuleNotFoundError: No module named 'yolov6'
Paula DerrengerUltralytics(已编辑)@kadirnar hi there!
Yes, the Ultralytics library does support YOLOv6 models. It seems like you might be encountering a
ModuleNotFoundErrorbecause the YOLOv6 model isn't being recognized. Let's ensure you're using the latest versions oftorchandultralytics. Please update your packages and try again:pip install --upgrade torch ultralyticsHere's a quick example to get you started with YOLOv6 using the Ultralytics library:
Python
from ultralytics import YOLO # Load a YOLOv6n model model = YOLO("yolov6n.yaml") # Train the model on the COCO8 example dataset for 100 epochs results = model.train(data="coco8.yaml", epochs=100, imgsz=640) # Run inference with the trained model on an image results = model("path/to/bus.jpg")CLI
# Train YOLOv6n model yolo train model=yolov6n.yaml data=coco8.yaml epochs=100 imgsz=640 # Run inference with your trained weights yolo predict model=path/to/best.pt source=path/to/bus.jpgIf you continue to face issues, please provide a minimum reproducible example so we can better assist you. You can refer to our guide on creating a minimum reproducible example here: Minimum Reproducible Example.
Feel free to reach out if you have any more questions! 😊
akhilesh99sharma
There are AP and AR values for results but not precision and recall. I need to compare precision and recall values for different YOLO versions (v5,v6,v7 etc.) on my custom dataset. How to get precision and recall values for YOLOv6 evaluation?
Paula DerrengerUltralytics(已编辑)Hey there! 👋
You don't need to compute precision and recall by hand: validation already reports them. After
model.val(), the results object holds them directly:from ultralytics import YOLO # Load your trained model model = YOLO("path/to/your/custom-yolov6-model.pt") # Run validation results = model.val(data="path/to/your/dataset.yaml") print(f"Precision: {results.box.mp}, Recall: {results.box.mr}") # mean over all classes print(results.box.p, results.box.r) # per-class precision and recallHope this helps, and happy comparing across YOLO versions! 🚀
akhilesh99sharma
Hello , I tried but was still not able to get these values, could you please help me with that?
Paula DerrengerUltralytics(已编辑)Hey there! 😊
Precision and recall are reported by Ultralytics validation, so you don't need to count TP/FP/FN yourself. After
results = model.val(data="path/to/dataset.yaml"), useresults.box.mp(mean precision),results.box.mr(mean recall), andresults.box.p/results.box.rfor per-class values.If you need them computed from raw counts, precision = TP / (TP + FP) and recall = TP / (TP + FN), where the counts come from matching predictions to ground-truth boxes at an IoU threshold.
Hope this helps! Let me know if there's anything else I can do for you. Happy modeling! 🚀
akhilesh99sharma
Hello, I tried doing it but was not able to do so. I get the predictions json file in the val folder but don't know how to compare it with the labels to get TP, FP etc. Can you please help me with that? I need to compare results of YOLOv6 with v8, v9 but I am not getting precision and recall values in v6 , I get average precision and average recall
Paula DerrengerUltralytics(已编辑)@akhilesh99sharma hey there! 🌞
You can get precision and recall directly from validation without processing the predictions JSON yourself. After
results = model.val(data="path/to/dataset.yaml"), useresults.box.mp(mean precision),results.box.mr(mean recall), andresults.box.p/results.box.rfor per-class values.If you still need TP, FP and FN counts from the saved predictions JSON, you will have to match predicted boxes to ground-truth boxes per image using an IoU threshold. The confusion matrix saved in the run folder (
confusion_matrix.png, ormodel.val(plots=True)) also shows these counts per class.For comparing across YOLO versions, run each model with consistent settings on your custom dataset and read the same metrics from each.
I hope this simplifies the process for you! 🚀 Let me know if you need further assistance.