RTDETRv2 与 YOLOX
构建实时目标检测系统的开发者可以选择多种架构。其中两个值得关注的模型是基于 Transformer 的 RTDETRv2 和卷积神经网络(CNN)YOLOX。两者都推动了实时检测的发展,但在视觉识别方面采用了截然不同的方法。
本指南介绍这两种模型的架构、性能指标和理想部署场景,并展示 Ultralytics YOLO26 如何基于这些基础实现更高的精度、效率和易用性。
RTDETRv2:实时检测 Transformer#
作为最初 RT-DETR 的后续版本,RTDETRv2 采用 Transformer 架构进行实时目标检测。通过省去 非极大值抑制(NMS),它简化了推理流程。
- 作者: Wenyu Lv、Yian Zhao、Qinyao Chang、Kui Huang、Guanzhong Wang 和 Yi Liu
- 组织: 百度
- 日期: 2024-07-24
- 链接:arXiv 论文、官方 GitHub、文档
架构与设计#
RTDETRv2 依靠 Transformer 的自注意力机制捕获整幅图像的全局上下文信息,从而直接预测边界框和类别概率。它的多尺度特征有助于在杂乱环境中识别小目标。
虽然 Transformer 擅长捕获全局上下文,但其自注意力机制会随序列长度呈平方级增长,因此与传统 CNN 相比,训练时往往会消耗多得多的 CUDA 内存。
优势与劣势#
RTDETRv2 的主要优势是原生端到端设计。跳过 NMS 后,它不会出现密集且重叠的预测所导致的延迟峰值。不过,Transformer 模块的计算开销很大,训练和部署都需要大量 GPU 资源,因此不太适合资源受限的边缘设备或较旧的移动硬件。
YOLOX:推动无锚框 CNN 的发展#
YOLOX 旨在弥合学术研究与工业应用之间的差距,为广受欢迎的 YOLO 模型系列引入了解耦检测头和无锚框设计。
架构与设计#
YOLOX 摒弃了传统的基于锚框的检测器,直接预测目标位置,无需预定义锚框。这简化了网络设计,并减少了实现最佳性能所需的启发式调优参数。此外,YOLOX 采用解耦头,将分类和回归任务分开处理,从而加快训练收敛。
优势与劣势#
无锚框设计让 YOLOX 能够适配各种计算机视觉任务,也更容易在自定义数据集上训练。YOLOX-Nano 等最轻量的变体适用于移动设备和低功耗物联网设备。不过,YOLOX 早于无需 NMS 的检测器,仍需依靠 NMS 后处理,因此在密集场景中会增加部署复杂度和延迟。
性能与指标对比#
下表比较了不同模型尺寸在 COCO 数据集上的速度、精度(mAP)和参数效率。
| 模型 | 尺寸 (像素) | mAPval50-95 | 速度 CPU ONNX (毫秒) | 速度 T4 TensorRT10 (ms) | 参数 (M) | FLOPs (B) |
|---|---|---|---|---|---|---|
| RTDETRv2-s | 640 | 48.1 | - | 5.03 | 20 | 60 |
| RTDETRv2-m | 640 | 51.9 | - | 7.51 | 36 | 100 |
| RTDETRv2-l | 640 | 53.4 | - | 9.76 | 42 | 136 |
| RTDETRv2-x | 640 | 54.3 | - | 15.03 | 76 | 259 |
| YOLOXnano | 416 | 25.8 | - | - | 0.91 | 1.08 |
| YOLOXtiny | 416 | 32.8 | - | - | 5.06 | 6.45 |
| YOLOXs | 640 | 40.5 | - | 2.56 | 9.0 | 26.8 |
| YOLOXm | 640 | 46.9 | - | 5.43 | 25.3 | 73.8 |
| YOLOXl | 640 | 49.7 | - | 9.04 | 54.2 | 155.6 |
| YOLOXx | 640 | 51.1 | - | 16.1 | 99.1 | 281.9 |
在可比尺寸下,RTDETRv2 的精度都更高。RTDETRv2-x 的 mAP 达到 54.3,高于 YOLOXx 的 51.1;它在 T4 GPU 上也更快(15.03 ms 对比 16.1 ms),参数更少(76M 对比 99.1M)。YOLOX 的优势在于小尺寸模型:YOLOXs 运行时间为 2.56 ms,参数量为 9.0M(mAP 为 40.5);YOLOX-Nano 和 YOLOX-Tiny 则提供了参数量低于 6M 的选项,而 RTDETRv2 没有这类型号。
Ultralytics 的优势:YOLO26 登场#
许多项目需要一个兼具高精度、快速推理和易用生态系统的单一模型。Ultralytics YOLO26 于 2026 年 1 月发布,正是为此而设计。
YOLO26 的关键创新#
- 端到端无 NMS 设计:在 YOLOv10 为 YOLO 模型引入的无 NMS 训练基础上,YOLO26 提供可选的无 NMS 检测头(
nms=False)。它能实现 RTDETRv2 的端到端推理,同时避免 Transformer 的高内存需求。 - MuSGD 优化器:受大语言模型(LLM)训练启发,混合式 MuSGD 优化器(结合 SGD 和 Muon)能够稳定训练并加快收敛。
- CPU 推理速度最高提升 43%:移除分布焦点损失(DFL)模块后,检测头更精简,更适合边缘计算和低功耗设备;与 YOLO11n 相比,YOLO26n 在 CPU(ONNX)上的速度最高提升 43%。
- ProgLoss + STAL:渐进式损失和小目标感知标签分配(STAL)可提升小目标识别能力,有助于解决航空影像和机器人应用中常见的难题。
灵活性与生态系统#
除了原始性能,Ultralytics Platform 还覆盖从数据到生产的完整流程。与静态学术代码库不同,Ultralytics 模型会持续维护,并通过单一 API 支持多种任务。无论你执行的是实例分割、姿态估计,还是旋转框(OBB)检测,工作流程都保持一致。
Ultralytics YOLO 模型在训练和推理期间的内存需求也较低,因此研究人员可以在消费级硬件上使用比内存占用较大的 Transformer 架构更大的批次。
训练代码示例#
只需几行代码即可训练 YOLO26 模型,Ultralytics 软件包会处理数据加载和默认超参数配置。
from ultralytics import YOLO
# Initialize the YOLO26 Nano model
model = YOLO("yolo26n.pt")
# Train the model on the standard COCO8 dataset
results = model.train(data="coco8.yaml", epochs=100, imgsz=640, batch=16)
# Validate the model's performance
metrics = model.val()
print(f"Validation mAP: {metrics.box.map}")
# Export to ONNX or TensorRT for rapid deployment
model.export(format="engine", device=0)实际应用与理想用例#
选择合适的架构取决于你的部署限制和可用硬件。
高保真云端处理#
如果你的应用运行在高端服务器 GPU 上,并且优先追求最高精度——例如分析密集的人群场景或处理高分辨率医学影像——RTDETRv2 的注意力机制会很有效。
旧版边缘设备部署#
对于较旧的手机或对 FLOPs 数量有严格限制的嵌入式硬件,轻量级 YOLOX-Nano(0.91M 参数,1.08B FLOPs)凭借简单的 CNN 架构仍是可行的备用方案。
现代标准:AIoT 与机器人#
对于大多数现代应用,包括智慧城市基础设施、零售分析和自主导航,我们推荐使用 Ultralytics YOLO26。相较于 YOLO11n,YOLO26n 的 CPU 推理速度最高提升 43%,适用于边缘计算;它可选的无 NMS 检测头还能提供低且稳定的延迟。配合 Ultralytics 文档和活跃的社区,团队可以快速完成从数据集标注到部署的整个流程。
使用 Ultralytics Platform 管理数据集、在云端训练模型,并大规模部署模型。
其他值得考虑的 Ultralytics 模型包括拥有广泛社区集成的 YOLOv8,以及在旧版流程中仍稳定可靠的 YOLOv5。对于新项目,我们建议从 YOLO26 开始。
评论6
提出问题、分享结果,或帮助其他人。
UltralyticsAssistantUltralytics
👋 Hello, thank you for opening a discussion and engaging with Ultralytics 🚀! For new users, we recommend visiting the Docs where you'll find detailed Python and CLI usage examples, as well as answers to many common questions.
If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us investigate further.
If your question is about custom training or model comparison ❓, please share as much detail as possible—such as dataset samples, training logs, or what specific performance metrics you're interested in. Don't forget to check out our Tips for Best Training Results for optimal guidance.
Join the Ultralytics community where you feel most comfortable:
- For real-time chat, head to Discord 🎧
- For in-depth discussions, visit Discourse
- Or explore threads on our Subreddit to share and learn with others
Upgrade
Please ensure you're using the latest
ultralyticspackage and all requirements in a Python>=3.8 environment with PyTorch>=1.8:pip install -U ultralyticsEnvironments
YOLO models can be run in any of the following up-to-date verified environments (with all dependencies, including CUDA/CUDNN, Python and PyTorch preinstalled):
- Notebooks with free GPU:
- Google Cloud Deep Learning VM. See GCP Quickstart Guide
- Amazon Deep Learning AMI. See AWS Quickstart Guide
- Docker Image. See Docker Quickstart Guide
Status
If this badge is green, all Ultralytics CI tests are currently passing! CI tests verify correct operation of all YOLO Modes and Tasks across macOS, Windows, and Ubuntu every 24 hours and on every commit.
This is an automated response and an Ultralytics engineer will assist you soon 😊
Glenn JocherUltralytics(已编辑)This page offers a valuable comparison between RTDETRv2 and YOLOX, highlighting their different strengths. If you have specific questions about these models, feel free to ask here. RTDETRv2 excels in accuracy (reaching 54.3% mAP) but demands more computational resources, while YOLOX stands out for efficiency and speed, making it ideal for edge devices. For those seeking alternatives with a balance of performance and usability, you might also consider Ultralytics YOLO26, which offers excellent performance across various computer vision tasks. What specific aspect of these models are you most interested in learning more about?
UltralyticsAssistantUltralytics
👋 Hello, thank you for starting this comparison discussion about RTDETRv2 and YOLOX! 🚀 For detailed guidance, we recommend checking out our Docs, which contain in-depth information, benchmarks, and usage examples that may help answer many of your questions.
If this is a 🐛 Bug Report, please provide a minimum reproducible example so we can assist you efficiently.
For model training or evaluation ❓ Questions, please share as many details as possible, such as dataset samples, training logs, or specific requirements, and review our Tips for Best Training Results.
Join the Ultralytics community in your preferred space! For real-time chat, visit our Discord 🎧. For topic-based discussions, check out Discourse, or connect with others on our Subreddit.
Upgrade
Make sure your
ultralyticspackage and all requirements are up to date in a Python>=3.8 environment with PyTorch>=1.8:pip install -U ultralyticsEnvironments
YOLO models can be run in these verified environments:
- Notebooks with free GPU:
- Google Cloud Deep Learning VM: GCP Quickstart Guide
- Amazon Deep Learning AMI: AWS Quickstart Guide
- Docker Image: Docker Quickstart Guide
Status
A green badge means all Ultralytics CI tests are passing. CI covers all YOLO Modes and Tasks across macOS, Windows, and Ubuntu.
This is an automated response 🤖. An Ultralytics engineer will review your discussion and provide further assistance soon!
Glenn JocherUltralytics(已编辑)Welcome to the RTDETRv2 vs YOLOX comparison discussion! This page highlights two powerful object detection approaches with different strengths: RTDETRv2 leverages transformer architecture for higher accuracy in complex scenes (54.3% mAP for RTDETRv2-x), while YOLOX offers exceptional efficiency with faster inference speed (2.56ms for YOLOX-s on T4 TensorRT).
Your use case should guide your choice - RTDETRv2 excels when maximum accuracy is critical and GPU resources are available, while YOLOX is ideal for edge devices and real-time applications with limited resources.
If you're looking for models within a comprehensive ecosystem, you might also consider Ultralytics YOLO26 which balances performance with ease of use.
Feel free to post any questions about these models or their implementation in your specific applications. The Ultralytics team is here to help!
- Notebooks with free GPU:
UltralyticsAssistantUltralytics
👋 Hello, thank you for starting this discussion and sharing your interest in comparing object detection models like RTDETRv2 and YOLOX 🚀! For a detailed overview, the Ultralytics Docs offer a wealth of information, including the comparison page you linked, which highlights model strengths, performance, and use cases.
If you have specific questions or encounter any issues related to these models, please provide as much detail as possible.
- If this is a 🐛 Bug Report, please include a minimum reproducible example to help us assist you.
- For custom training ❓ questions, adding dataset samples and training logs can be very helpful. Make sure to review our Training Tips for best results.
Connect with the Ultralytics community in your preferred way! For real-time help, join our Discord 🎧. In-depth posts and discussions are found on Discourse, and our Subreddit is great for sharing experiences and solutions.
Upgrade
To ensure the best experience and access to the latest features and fixes, please upgrade the
ultralyticspackage and all requirements in a Python>=3.8 environment with PyTorch>=1.8:pip install -U ultralyticsEnvironments
YOLO models can be run in any of these verified environments with all dependencies preinstalled:
- Notebooks with free GPU:
- Google Cloud Deep Learning VM (GCP Quickstart Guide)
- Amazon Deep Learning AMI (AWS Quickstart Guide)
- Docker Image (Docker Quickstart Guide)
Status
A green badge means all Ultralytics CI tests are passing, ensuring YOLO Modes and Tasks work across macOS, Windows, and Ubuntu.
This is an automated response 🤖—an Ultralytics engineer will review your discussion and assist you soon!
Glenn JocherUltralytics(已编辑)Welcome to the discussion about RTDETRv2 and YOLOX object detection models! Both offer different strengths - RTDETRv2 provides higher accuracy through its transformer architecture, while YOLOX excels in speed and efficiency on resource-constrained devices.
If you have specific questions about implementing either model, performance tuning, or need help choosing between them for your particular use case, please share your questions here. Our team monitors these discussions to provide technical guidance and support.
For hands-on users interested in similar models with Ultralytics integration, YOLO26 offers an excellent balance of speed and accuracy with full support in our ecosystem.