RF-DETR 论文解读:Roboflow实时Transformer目标检测SOTA,COCO 78.5 AP

RF-DETR 论文解读:Roboflow实时Transformer目标检测SOTA,COCO 78.5 AP

论文: RF-DETR: A Real-Time Object Detection and Segmentation Model Architecture
机构: Roboflow
会议: ICLR 2026
开源: https://github.com/roboflow/rf-detr
许可证: Apache 2.0(开源版本)/ PML 1.0(Plus版本)


核心突破

指标 RF-DETR-2XL YOLO11-X 提升
COCO AP50:95 60.1 50.9 +18%
COCO AP50 78.5 66.1 +19%
实时性 17.2ms 10.5ms 可接受
关键点检测 ✅ 支持 ✅ 支持 71.8 AP
实例分割 ✅ 支持 ✅ 支持 49.9 mask AP

技术架构

核心创新

graph TD
    A[RF-DETR架构] --> B[DINOv2 ViT Backbone]
    B --> C[多尺度特征金字塔]
    C --> D[DETR Decoder]
    D --> E[目标检测头]
    D --> F[实例分割头]
    D --> G[关键点检测头]
    
    H[创新点] --> I[神经架构搜索NAS]
    H --> J[统一API三任务]
    H --> K[TensorRT优化]

模型规格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
RF-DETR 模型规格对比

核心特点:
1. DINOv2 ViT backbone(自监督预训练)
2. 支持检测+分割+关键点三任务
3. 神经架构搜索(NAS)自动调优
4. TensorRT FP16优化
"""

MODEL_SPECS = {
# 目标检测模型
"RF-DETR-N": {
"COCO_AP50": 67.6,
"COCO_AP5095": 48.4,
"Latency_ms": 2.3,
"Params_M": 30.5,
"Resolution": "384x384",
"License": "Apache 2.0"
},

"RF-DETR-S": {
"COCO_AP50": 72.1,
"COCO_AP5095": 53.0,
"Latency_ms": 3.5,
"Params_M": 32.1,
"Resolution": "512x512",
"License": "Apache 2.0"
},

"RF-DETR-M": {
"COCO_AP50": 73.6,
"COCO_AP5095": 54.7,
"Latency_ms": 4.4,
"Params_M": 33.7,
"Resolution": "576x576",
"License": "Apache 2.0"
},

"RF-DETR-L": {
"COCO_AP50": 75.1,
"COCO_AP5095": 56.5,
"Latency_ms": 6.8,
"Params_M": 33.9,
"Resolution": "704x704",
"License": "Apache 2.0"
},

"RF-DETR-XL": {
"COCO_AP50": 77.4,
"COCO_AP5095": 58.6,
"Latency_ms": 11.5,
"Params_M": 126.4,
"Resolution": "700x700",
"License": "PML 1.0" # Plus版本
},

"RF-DETR-2XL": {
"COCO_AP50": 78.5,
"COCO_AP5095": 60.1,
"Latency_ms": 17.2,
"Params_M": 126.9,
"Resolution": "880x880",
"License": "PML 1.0"
}
}

# 实例分割模型
SEG_SPECS = {
"RF-DETR-Seg-N": {"AP50": 63.0, "AP5095": 40.3, "ms": 3.4},
"RF-DETR-Seg-S": {"AP50": 66.2, "AP5095": 43.1, "ms": 4.4},
"RF-DETR-Seg-M": {"AP50": 68.4, "AP5095": 45.3, "ms": 5.9},
"RF-DETR-Seg-L": {"AP50": 70.5, "AP5095": 47.1, "ms": 8.8},
"RF-DETR-Seg-2XL": {"AP50": 73.1, "AP5095": 49.9, "ms": 21.8}
}

# 关键点检测
KP_SPECS = {
"RF-DETR-Keypoint": {"AP5095": 71.8, "ms": 9.7}
}

快速使用

安装

1
2
3
4
5
6
7
8
# 安装开源版本
pip install rfdetr

# 安装Plus版本(XL/2XL)
pip install rfdetr[plus]

# 从源码安装(最新功能)
pip install https://github.com/roboflow/rf-detr/archive/refs/heads/develop.zip

目标检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
)

annotated_image.save("output.jpg")

实例分割

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from rfdetr import RFDETRSegMedium

# 加载分割模型
model = RFDETRSegMedium()

# 推理
detections = model.predict("image.jpg", threshold=0.5)

# 可视化掩码
annotated = sv.MaskAnnotator().annotate(
detections.metadata["source_image"],
detections
)
annotated = sv.LabelAnnotator().annotate(annotated, detections, labels)

关键点检测

1
2
3
4
5
# RF-DETR Keypoint (Preview)
from rfdetr import RFDETRKeypoint

model = RFDETRKeypoint()
keypoints = model.predict("person.jpg")

与YOLO对比

目标检测性能对比

模型 COCO AP50 COCO AP50:95 延迟(ms) 参数(M)
RF-DETR-M 73.6 54.7 4.4 33.7
YOLO11-M 64.1 48.6 5.1 20.1
YOLO26-M 69.7 52.5 4.4 20.1
LW-DETR-M 72.0 52.6 4.4 28.2

实例分割性能对比

模型 Mask AP50 Mask AP50:95 延迟(ms)
RF-DETR-Seg-M 68.4 45.3 5.9
YOLO11-M-Seg 60.0 38.5 6.9
YOLO26-M-Seg 67.8 44.0 6.32

关键点检测对比

模型 Keypoint AP50:95 延迟(ms)
RF-DETR-Keypoint 71.8 9.7
YOLO11-pose M 64.2 5.2
YOLO26-pose M 68.0 4.6

技术原理

DINOv2 Backbone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
RF-DETR 使用 DINOv2 ViT 作为backbone

DINOv2特点:
1. 自监督预训练(无需标签)
2. 强大的视觉表征能力
3. 多尺度特征金字塔
"""

import torch
import torch.nn as nn

class DINOv2Backbone(nn.Module):
"""
DINOv2 Vision Transformer Backbone

预训练权重来自:
- dinov2_small: 21M参数
- dinov2_base: 86M参数
- dinov2_large: 300M参数
- dinov2_giant: 1.1B参数
"""

def __init__(self, model_name='dinov2_base', pretrained=True):
super().__init__()

# 加载预训练模型
self.backbone = torch.hub.load(
'facebookresearch/dinov2',
model_name,
pretrained=pretrained
)

# 冻结部分层
self._freeze_layers()

def _freeze_layers(self):
"""冻结早期层,仅微调后期层"""
for name, param in self.backbone.named_parameters():
if 'blocks.0' in name or 'blocks.1' in name:
param.requires_grad = False

def forward(self, x):
"""
提取多尺度特征

Args:
x: 输入图像,shape=(B, 3, H, W)

Returns:
features: 多尺度特征金字塔
"""
# DINOv2前向传播
features = self.backbone.get_intermediate_layers(
x,
n=[2, 5, 8, 11], # 多尺度层
return_class_token=True
)

return features

DETR Decoder

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class DETRDecoder(nn.Module):
"""
DETR Decoder for RF-DETR

特点:
1. 可变形注意力(Deformable Attention)
2. 多尺度特征融合
3. 查询嵌入优化
"""

def __init__(self, hidden_dim=256, num_heads=8, num_layers=6):
super().__init__()

# 查询嵌入
self.query_embed = nn.Embedding(100, hidden_dim) # 100个查询

# 解码器层
decoder_layer = nn.TransformerDecoderLayer(
d_model=hidden_dim,
nhead=num_heads,
dim_feedforward=1024,
dropout=0.1,
batch_first=True
)

self.decoder = nn.TransformerDecoder(
decoder_layer,
num_layers=num_layers
)

# 检测头
self.class_head = nn.Linear(hidden_dim, 91) # COCO 91类
self.box_head = nn.Linear(hidden_dim, 4) # (cx, cy, w, h)

def forward(self, memory, query_embed):
"""
解码

Args:
memory: 编码器输出
query_embed: 查询嵌入

Returns:
outputs: {
'pred_logits': 类别预测,
'pred_boxes': 框预测
}
"""
# 解码
hs = self.decoder(query_embed, memory)

# 预测
pred_logits = self.class_head(hs)
pred_boxes = self.box_head(hs).sigmoid()

return {
'pred_logits': pred_logits,
'pred_boxes': pred_boxes
}

对IMS开发的价值

1. 乘员检测

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
RF-DETR 用于IMS乘员检测

优势:
- 78.5 AP50,比YOLO11高19%
- 支持小目标检测(儿童)
- 实例分割可区分遮挡
"""

# 乘员检测配置
OCCUPANT_CLASSES = [
'driver', 'front_passenger',
'rear_left', 'rear_middle', 'rear_right',
'child_seat'
]

class OccupantDetector:
def __init__(self):
self.model = RFDETRMedium()
# 微调到乘员数据集
self.model.load_state_dict(
torch.load('occupant_rfdetr.pth')
)

def detect(self, frame):
"""检测乘员"""
detections = self.model.predict(frame, threshold=0.5)

occupants = []
for det in detections:
occupants.append({
'class': det.class_name,
'bbox': det.bbox,
'confidence': det.confidence
})

return occupants

2. 关键点检测(姿态估计)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
RF-DETR Keypoint 用于OOP异常姿态检测

应用场景:
- 检测驾驶员是否趴在方向盘上
- 检测乘客是否躺倒在座椅上
- 检测儿童是否被遗忘在后排
"""

# COCO 17关键点
COCO_KEYPOINTS = [
'nose', 'left_eye', 'right_eye', 'left_ear', 'right_ear',
'left_shoulder', 'right_shoulder', 'left_elbow', 'right_elbow',
'left_wrist', 'right_wrist', 'left_hip', 'right_hip',
'left_knee', 'right_knee', 'left_ankle', 'right_ankle'
]

class OOPDetector:
"""异常姿态检测器"""

def __init__(self):
self.keypoint_model = RFDETRKeypoint()

def detect_abnormal_posture(self, keypoints):
"""
检测异常姿态

Args:
keypoints: shape=(17, 3) - (x, y, visibility)

Returns:
is_abnormal: bool
posture_type: str
"""
# 检测趴在方向盘上
if self._is_head_on_wheel(keypoints):
return True, 'head_on_wheel'

# 检测躺倒
if self._is_lying_down(keypoints):
return True, 'lying_down'

# 检测前倾
if self._is_forward_lean(keypoints):
return True, 'forward_lean'

return False, 'normal'

def _is_head_on_wheel(self, kp):
"""头趴在方向盘上"""
# 鼻子高度低于肩膀
nose_y = kp[0, 1]
shoulder_y = (kp[5, 1] + kp[6, 1]) / 2

return nose_y > shoulder_y + 50 # 阈值可调

3. 实例分割(安全带检测)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""
RF-DETR-Seg 用于安全带误用检测

策略:
1. 实例分割区分安全带与身体
2. 检测安全带是否正确佩戴
3. 检测腰带位置是否错误
"""

class SeatbeltDetector:
def __init__(self):
self.model = RFDETRSegMedium()

def detect_misuse(self, frame):
"""检测安全带误用"""
detections = self.model.predict(frame, threshold=0.5)

for det in detections:
if det.class_name == 'seatbelt':
mask = det.mask

# 分析安全带位置
# 1. 斜带是否从肩部穿过
# 2. 腰带是否位于髋部

is_correct = self._check_position(mask)

if not is_correct:
return {
'misuse': True,
'type': 'incorrect_position'
}

return {'misuse': False}

部署指南

TensorRT优化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 导出ONNX
python -c "
from rfdetr import RFDETRMedium
model = RFDETRMedium()
model.export_onnx('rfdetr_m.onnx')
"

# TensorRT转换
trtexec --onnx=rfdetr_m.onnx \
--saveEngine=rfdetr_m.trt \
--fp16 \
--minShapes=input:1x3x576x576 \
--optShapes=input:1x3x576x576 \
--maxShapes=input:4x3x576x576

边缘设备性能

设备 模型 延迟 吞吐量
NVIDIA T4 RF-DETR-M 4.4ms 227 fps
Jetson Orin RF-DETR-S 8ms 125 fps
Jetson Nano RF-DETR-N 25ms 40 fps

总结

RF-DETR优势

  1. 精度领先:COCO 78.5 AP,比YOLO11高19%
  2. 三任务统一:检测+分割+关键点,一套API
  3. 开源友好:Apache 2.0许可证,可商用
  4. NAS自动调优:Roboflow平台支持自定义架构搜索

IMS应用价值

应用场景 RF-DETR能力
乘员检测 78.5 AP50高精度
OOP姿态检测 71.8 Keypoint AP
安全带分割 49.9 Mask AP
边缘部署 4.4ms实时推理

参考资料

  1. GitHubhttps://github.com/roboflow/rf-detr
  2. Roboflow Bloghttps://blog.roboflow.com/rf-detr/
  3. DINOv2论文https://arxiv.org/abs/2304.07193
  4. DETR论文https://arxiv.org/abs/2005.12872

相关文章:


RF-DETR 论文解读:Roboflow实时Transformer目标检测SOTA,COCO 78.5 AP
https://dapalm.com/2026/07/15/2026-07-15-rf-detr-roboflow-realtime-transformer-object-detection-iclr-2026/
作者
Mars
发布于
2026年7月15日
许可协议