ITADN
roboflow/rf-detr
README.md
以下内容由 AI 翻译,如有问题请点此提交 issue 反馈

RF-DETR:实时 SOTA 目标检测、实例分割与关键点检测


RF-DETR 是由 Roboflow 开发的一种用于目标检测、实例分割和关键点检测(预览)的实时 transformer 架构。基于 DINOv2 视觉 transformer 骨干网络,RF-DETR 在 Microsoft COCORF100-VL 上实现了最先进的精度与延迟权衡。

RF-DETR 使用 DINOv2 视觉 transformer 骨干网络,并通过单一、一致的 API 支持目标检测、实例分割和关键点检测(预览)。开源 rfdetr 包和指定为 Apache 的模型以 Apache 2.0 许可证发布,而 Plus 组件(rfdetr_plus,包括 RF-DETR-XL/2XL 检测模型)则采用 PML 1.0 许可证。

已发布的 RF-DETR 尺寸是通过神经架构搜索(NAS)创建的——同样的 NAS 方法现已在 Roboflow 平台 上可用,因此您可以为自己的数据集发现最佳架构。更多信息请参阅 NAS 文档

https://github.com/user-attachments/assets/add23fd1-266f-4538-8809-d7dd5767e8e6

安装

要安装 RF-DETR,请在 rfdetr 包中,使用 pipPython>=3.10 环境中进行安装。

pip install rfdetr
从源代码安装

通过从源代码安装 RF-DETR,您可以探索尚未正式发布的最新特性和增强功能。请注意,这些更新仍处于开发阶段,可能不如最新发布的版本稳定。

pip install https://github.com/roboflow/rf-detr/archive/refs/heads/develop.zip

基准测试

RF-DETR 在目标检测和实例分割方面均取得了最先进的结果,基准测试在 Microsoft COCO 和 RF100-VL 上报告(RF100-VL 仅用于检测)。下图和下表比较了 RF-DETR 与其他顶级实时模型在检测和分割方面的精度与延迟。所有 COCO 精度数值均为内部针对每个所示模型进行测量,使用 pycocotools 在 SAB 上针对完整的 5,000 张图像 val2017 分割集计算得出,因此每一行都可直接比较,且可能与厂商报告的数值不同。唯一的例外是标记为 † 的行,这些数值引用自原作者的论文,未在 SAB 中进行测量。所有延迟数值均在 NVIDIA T4 上使用 TensorRT、FP16 和批处理大小 1 进行测量。参数量是部署(融合)nn.Module 参数量(model.parameters(),而非保存检查点的原始张量计数),标记为 † 的行除外,这些行是作者报告的计数。有关完整的基准测试方法和可复现性详情,请参阅 roboflow/sab.

检测

rf_detr_1-4_latency_accuracy_object_detection
查看目标检测基准测试数值
ArchitectureCOCO AP50COCO AP50:95RF100VL AP50RF100VL AP50:95Latency (ms)Params (M)ResolutionLicense
RF-DETR-N67.648.485.057.72.330.5384x384Apache 2.0
RF-DETR-S72.153.086.760.23.532.1512x512Apache 2.0
RF-DETR-M73.654.787.461.24.433.7576x576Apache 2.0
RF-DETR-L75.156.588.262.26.833.9704x704Apache 2.0
RF-DETR-XL △77.458.688.562.911.5126.4700x700PML 1.0
RF-DETR-2XL △78.560.189.063.217.2126.9880x880PML 1.0
YOLO11-N52.037.481.455.32.52.6640x640AGPL-3.0
YOLO11-S59.744.482.356.23.29.4640x640AGPL-3.0
YOLO11-M64.148.682.556.55.120.1640x640AGPL-3.0
YOLO11-L64.949.982.256.56.525.3640x640AGPL-3.0
YOLO11-X66.150.981.756.210.556.9640x640AGPL-3.0
YOLO26-N55.840.376.752.01.72.6640x640AGPL-3.0
YOLO26-S64.347.782.757.02.69.4640x640AGPL-3.0
YOLO26-M69.752.584.458.74.420.1640x640AGPL-3.0
YOLO26-L71.154.185.059.35.725.3640x640AGPL-3.0
YOLO26-X74.056.985.660.09.656.9640x640AGPL-3.0
LW-DETR-T60.742.984.757.11.912.1640x640Apache 2.0
LW-DETR-S66.848.085.057.42.614.6640x640Apache 2.0
LW-DETR-M72.052.686.859.84.428.2640x640Apache 2.0
LW-DETR-L74.656.187.461.56.946.8640x640Apache 2.0
LW-DETR-X76.958.387.962.113.0118.0640x640Apache 2.0
D-FINE-N60.242.784.458.22.13.8640x640Apache 2.0
D-FINE-S67.650.685.360.33.510.2640x640Apache 2.0
D-FINE-M72.655.085.560.65.419.2640x640Apache 2.0
D-FINE-L74.957.286.461.67.531.0640x640Apache 2.0
D-FINE-X76.859.386.962.211.562.0640x640Apache 2.0
SAM 3 †61.6~8501008x1008N/A

† 由 SAM 3 作者报告(arXiv:2511.16719, Table 36]),并非我们在 SAB 中测量的结果。该数值是 SAM 3 在完整的 RF100-VL 训练集上微调后的结果,这与上述 RF100VL 列的设置相同——SAM 3 的论文报告 LW-DETR-m 在该基准上为 59.8,与我们自己的测量结果一致,因此数据吻合。破折号表示 SAM 3 在此协议下未报告的结果。参数量是论文中所述的约 850 M(约 450 M 视觉 + 约 300 M 文本编码器 + 约 100 M 检测器/跟踪器)。

分割

rf_detr_1-4_latency_accuracy_instance_segmentation
查看实例分割基准数据
ArchitectureCOCO AP50COCO AP50:95Latency (ms)Params (M)ResolutionLicense
RF-DETR-Seg-N63.040.33.433.6312x312Apache 2.0
RF-DETR-Seg-S66.243.14.433.7384x384Apache 2.0
RF-DETR-Seg-M68.445.35.935.7432x432Apache 2.0
RF-DETR-Seg-L70.547.18.836.2504x504Apache 2.0
RF-DETR-Seg-XL72.248.813.538.1624x624Apache 2.0
RF-DETR-Seg-2XL73.149.921.838.6768x768Apache 2.0
YOLOv8-N-Seg45.628.33.53.4640x640AGPL-3.0
YOLOv8-S-Seg53.834.04.211.8640x640AGPL-3.0
YOLOv8-M-Seg58.237.37.027.3640x640AGPL-3.0
YOLOv8-L-Seg60.539.09.746.0640x640AGPL-3.0
YOLOv8-XL-Seg61.339.514.071.8640x640AGPL-3.0
YOLOv11-N-Seg47.830.03.62.9640x640AGPL-3.0
YOLOv11-S-Seg55.435.04.610.1640x640AGPL-3.0
YOLOv11-M-Seg60.038.56.922.4640x640AGPL-3.0
YOLOv11-L-Seg61.539.58.327.6640x640AGPL-3.0
YOLOv11-XL-Seg62.440.113.762.1640x640AGPL-3.0
YOLO26-N-Seg54.334.72.312.7640x640AGPL-3.0
YOLO26-S-Seg62.440.23.4710.4640x640AGPL-3.0
YOLO26-M-Seg67.844.06.3223.6640x640AGPL-3.0
YOLO26-L-Seg69.845.57.5828.0640x640AGPL-3.0
YOLO26-X-Seg71.646.812.9262.8640x640AGPL-3.0

关键点

RF-DETR Keypoint mAP vs latency chart comparing against YOLO26-pose and YOLO11-pose on MS COCO
查看关键点检测基准数据
ArchitectureCOCO AP50:95Latency (ms)Params (M)License
RF-DETR Keypoint (Preview)71.89.740.7Apache 2.0
YOLO11-pose N48.93.22.9AGPL-3.0
YOLO11-pose S57.53.49.9AGPL-3.0
YOLO11-pose M64.25.220.9AGPL-3.0
YOLO11-pose L65.26.626.2AGPL-3.0
YOLO11-pose X68.610.658.8AGPL-3.0
YOLO26-pose N55.91.92.9AGPL-3.0
YOLO26-pose S62.02.710.4AGPL-3.0
YOLO26-pose M68.04.621.5AGPL-3.0
YOLO26-pose L69.25.925.9AGPL-3.0
YOLO26-pose X71.09.857.6AGPL-3.0

Keypoint benchmarks report AP50:95 (OKS-based); this is the standard COCO keypoint comparison metric.

Roboflow 平台上的 NAS

RF100-VL 精度-延迟帕累托图,显示在 Roboflow 平台上训练的 RF-DETR NAS 优于论文中的 NAS 和命名配置

自论文发布以来,我们已在 Roboflow 平台上进一步提升了 RF-DETR NAS 的训练。单次训练运行即可提供所有模型尺寸,其结果不仅超越了开源检查点,也超越了我们论文中的 NAS 结果。立即试用!

运行模型

检测

RF-DETR 提供多种模型尺寸,范围从 Nano 到 2XLarge。若要使用不同的模型尺寸,请将下方代码片段中的类名替换为表格中的另一个类。

import supervision as sv
from rfdetr import RFDETRMedium
from rfdetr.assets.coco_classes import COCO_CLASSES

model = RFDETRMedium()

detections = model.predict("https://media.roboflow.com/dog.jpg", threshold=0.5)

labels = [f"{COCO_CLASSES[class_id]}" for class_id in detections.class_id]

annotated_image = sv.BoxAnnotator().annotate(detections.metadata["source_image"], detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections, labels)

注意: COCO_CLASSES 适用于 COCO 预训练模型。对于微调后的模型,请改用 detections.data["class_name"] —— 它从检查点中解析类别名称,同时适用于 COCO 和自定义数据集。

使用 Inference 运行 RF-DETR

你也可以使用 Inference 库运行 RF-DETR 模型。要切换模型大小,请从下表中选择相应的推理包别名。

import requests
import supervision as sv
from PIL import Image
from inference import get_model

model = get_model("rfdetr-medium")

image = Image.open(requests.get("https://media.roboflow.com/dog.jpg", stream=True).raw)
predictions = model.infer(image, confidence=0.5)[0]
detections = sv.Detections.from_inference(predictions)

annotated_image = sv.BoxAnnotator().annotate(image, detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections)
SizeRF-DETR package classInference package aliasCOCO AP50COCO AP50:95Latency (ms)Params (M)ResolutionLicense
NRFDETRNanorfdetr-nano67.648.42.330.5384x384Apache 2.0
SRFDETRSmallrfdetr-small72.153.03.532.1512x512Apache 2.0
MRFDETRMediumrfdetr-medium73.654.74.433.7576x576Apache 2.0
LRFDETRLargerfdetr-large75.156.56.833.9704x704Apache 2.0
XLRFDETRXLargerfdetr-xlarge77.458.611.5126.4700x700PML 1.0
2XLRFDETR2XLargerfdetr-2xlarge78.560.117.2126.9880x880PML 1.0

△ 需要 rfdetr_plus 扩展:pip install rfdetr[plus]。详见 License

分割

RF-DETR 支持实例分割,模型尺寸从 Nano 到 2XLarge。若要使用不同的模型尺寸,请将下方代码片段中的类名替换为表格中的另一个类。

import supervision as sv
from rfdetr import RFDETRSegMedium
from rfdetr.assets.coco_classes import COCO_CLASSES

model = RFDETRSegMedium()

detections = model.predict("https://media.roboflow.com/dog.jpg", threshold=0.5)

labels = [f"{COCO_CLASSES[class_id]}" for class_id in detections.class_id]

annotated_image = sv.MaskAnnotator().annotate(detections.metadata["source_image"], detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections, labels)
使用推理运行 RF-DETR-Seg

您也可以使用 Inference 库运行 RF-DETR-Seg 模型。要切换模型大小,请从下表中选择相应的推理包别名。

import requests
import supervision as sv
from PIL import Image
from inference import get_model

model = get_model("rfdetr-seg-medium")

image = Image.open(requests.get("https://media.roboflow.com/dog.jpg", stream=True).raw)
predictions = model.infer(image, confidence=0.5)[0]
detections = sv.Detections.from_inference(predictions)

annotated_image = sv.MaskAnnotator().annotate(image, detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections)
SizeRF-DETR package classInference package aliasCOCO AP50COCO AP50:95Latency (ms)Params (M)ResolutionLicense
NRFDETRSegNanorfdetr-seg-nano63.040.33.433.6312x312Apache 2.0
SRFDETRSegSmallrfdetr-seg-small66.243.14.433.7384x384Apache 2.0
MRFDETRSegMediumrfdetr-seg-medium68.445.35.935.7432x432Apache 2.0
LRFDETRSegLargerfdetr-seg-large70.547.18.836.2504x504Apache 2.0
XLRFDETRSegXLargerfdetr-seg-xlarge72.248.813.538.1624x624Apache 2.0
2XLRFDETRSeg2XLargerfdetr-seg-2xlarge73.149.921.838.6768x768Apache 2.0

关键点

RF-DETR 支持关键点检测(预览),使用 RFDETRKeypointPreview,在 COCO 人体关键点上预训练。

from rfdetr import RFDETRKeypointPreview

model = RFDETRKeypointPreview()
key_points = model.predict("image.jpg", threshold=0.5)
SizeRF-DETR package classCOCO AP50:95Latency (ms)Params (M)ResolutionLicense
Keypoint (Preview)RFDETRKeypointPreview71.89.740.7576x576Apache 2.0

训练模型

RF-DETR 支持目标检测、实例分割和关键点检测(预览)的训练。您可以在 Google Colab 或直接在 Roboflow 平台上训练模型。下方您将找到一个逐步的视频微调教程。

rf-detr-tutorial-banner

文档

请访问我们的文档网站,了解更多关于如何使用 RF-DETR 的信息。

许可证

许可证按组件划分:

  • 开源 rfdetr 包和指定为 Apache 的模型权重采用 Apache License 2.0 许可。参见 LICENSE
  • Plus 组件,包括 rfdetr_plus 扩展以及 RF-DETR-XL / RF-DETR-2XL 检测模型,采用 PML 1.0 许可。

致谢

我们的工作基于 LW-DETRDINOv2Deformable DETR。感谢他们的作者们出色的工作!

引用

如果您认为我们的工作对您的研究有帮助,请考虑引用以下 BibTeX 条目。

@inproceedings{robinson2026rfdetr,
  title     = {RF-DETR: Real-Time Detection Transformer},
  author    = {Robinson, Isaac and Robicheaux, Peter and Popov, Matvei and Ramanan, Deva and Peri, Neehar},
  booktitle = {International Conference on Learning Representations (ICLR)},
  year      = {2026},
  url       = {https://arxiv.org/abs/2511.09554}
}

贡献

我们欢迎并感谢所有贡献!如果您发现任何问题或错误、有疑问,或希望建议新功能,请提交 issue 或 pull request。通过分享您的想法和改进,您帮助让 RF-DETR 对每个人变得更好。