Skip to content

Commit 03aa832

Browse files
authored
Merge pull request #377 from roboflow/segmentation
Segmentation
2 parents ad27115 + 7a5a0e0 commit 03aa832

28 files changed

+1447
-222
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,10 @@ cython_debug/
173173
# PyPI configuration file
174174
.pypirc
175175

176-
.idea/
176+
.idea/
177+
178+
# model artifacts
179+
rf-detr*
180+
output/*
181+
182+
train_test.py

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RF-DETR: SOTA Real-Time Object Detection Model
1+
# RF-DETR: SOTA Real-Time Detection and Segmentation Model
22

33
[![version](https://badge.fury.io/py/rfdetr.svg)](https://badge.fury.io/py/rfdetr)
44
[![downloads](https://img.shields.io/pypi/dm/rfdetr)](https://pypistats.org/packages/rfdetr)
@@ -10,24 +10,31 @@
1010
[![roboflow](https://raw.githubusercontent.com/roboflow-ai/notebooks/main/assets/badges/roboflow-blogpost.svg)](https://blog.roboflow.com/rf-detr)
1111
[![discord](https://img.shields.io/discord/1159501506232451173?logo=discord&label=discord&labelColor=fff&color=5865f2&link=https%3A%2F%2Fdiscord.gg%2FGbfgXGJ8Bk)](https://discord.gg/GbfgXGJ8Bk)
1212

13-
RF-DETR is a real-time, transformer-based object detection model developed by Roboflow and released under the Apache 2.0 license.
13+
RF-DETR is a real-time, transformer-based object detection and instance segmentation model architecture developed by Roboflow and released under the Apache 2.0 license.
1414

15-
RF-DETR-N outperforms YOLO11-N by 10 mAP points on the [Microsoft COCO](https://cocodataset.org/#home) benchmark while running faster at inference. On [RF100-VL](https://github.com/roboflow/rf100-vl), RF-DETR achieves state-of-the-art results, with RF-DETR-M beating YOLO11-M by an average of 5 mAP points across aerial datasets including drone, satellite, and radar.
15+
RF-DETR is the first real-time model to exceed 60 AP on the [Microsoft COCO object detection benchmark](https://cocodataset.org/#home) alongside competitive performance at base sizes. It also achieves state-of-the-art performance on [RF100-VL](https://github.com/roboflow/rf100-vl), an object detection benchmark that measures model domain adaptability to real world problems. RF-DETR is fastest and most accurate for its size when compared current real-time objection models.
16+
17+
On image segmentation, RF-DETR Seg (Preview) is 3x faster and more accurate than the largest YOLO when evaluated on the Microsoft COCO Segmentation benchmark, defining a new real-time state-of-the-art for the industry-standard benchmark in segmentation model evaluation.
1618

1719
[![rf-detr-tutorial-banner](https://github.com/user-attachments/assets/555a45c3-96e8-4d8a-ad29-f23403c8edfd)](https://youtu.be/-OvpdLAElFA)
1820

1921
## News
2022

21-
- `2025/09/02`: RF-DETR fine-tuning YouTube tutorial released. Learn step-by-step how to fine-tune RF-DETR on your custom dataset.
22-
- `2025/07/23`: Released three new checkpoints for RF-DETR: Nano, Small, and Medium.
23-
- `2025/05/16`: Added `optimize_for_inference` method, improving native PyTorch inference speed by up to 2x depending on platform.
24-
- `2025/04/03`: Introduced early stopping, gradient checkpointing, metric saving, training resume, TensorBoard, and W&B logging.
25-
- `2025/03/20`: Released RF-DETR real-time object detection model. Code and checkpoints for RF-DETR-Large and RF-DETR-Base are available.
23+
- `2025/10/02`: We release RF-DETR-Seg (Preview), a preview of our instance segmentation head for RF-DETR.
24+
- `2025/07/23`: We release three new checkpoints for RF-DETR: Nano, Small, and Medium.
25+
- RF-DETR Base is now deprecated. We recommend using RF-DETR Medium which offers subtantially better accuracy at comparable latency.
26+
- `2025/03/20`: We release RF-DETR real-time object detection model. **Code and checkpoint for RF-DETR-large and RF-DETR-base are available.**
27+
- `2025/04/03`: We release early stopping, gradient checkpointing, metrics saving, training resume, TensorBoard and W&B logging support.
28+
- `2025/05/16`: We release an 'optimize_for_inference' method which speeds up native PyTorch by up to 2x, depending on platform.
2629

2730
## Results
2831

2932
RF-DETR achieves state-of-the-art performance on both the Microsoft COCO and the RF100-VL benchmarks.
3033

34+
The below tables shows how RF-DETR performs when validated on the Microsoft COCO benchmark for object detection and image segmentation.
35+
36+
### Object Detection Benchmarks
37+
3138
![rf-detr-coco-rf100-vl-9](https://media.roboflow.com/rfdetr/pareto1.png)
3239

3340
| Architecture | COCO AP<sub>50</sub> | COCO AP<sub>50:95</sub> | RF100VL AP<sub>50</sub> | RF100VL AP<sub>50:95</sub> | Latency (ms) | Params (M) | Resolution |
@@ -51,6 +58,28 @@ RF-DETR achieves state-of-the-art performance on both the Microsoft COCO and the
5158

5259
_We are actively working on RF-DETR Large and X-Large models using the same techniques we used to achieve the strong accuracy that RF-DETR Medium attains. This is why RF-DETR Large and X-Large is not yet reported on our pareto charts and why we haven't benchmarked other models at similar sizes. Check back in the next few weeks for the launch of new RF-DETR Large and X-Large models._
5360

61+
### Instance Segmentation Benchmarks
62+
63+
![rf-detr-coco-rf100-vl-9](https://media.roboflow.com/rfdetr/pareto_segmentation.png)
64+
65+
| Model Name | Reported Latency | Reported mAP | Measured Latency | Measured mAP |
66+
|-------------------------|------------------|--------------|------------------|--------------|
67+
| RF-DETR Seg-Preview@312 | | | 3.3 | 39.4 |
68+
| YOLO11n-Seg | 1.8 | 32.0 | 3.6 | 30.0 |
69+
| YOLOv8n-Seg | | 30.5 | 3.5 | 28.3 |
70+
| RF-DETR Seg-Preview@384 | | | 4.5 | 42.7 |
71+
| YOLO11s-Seg | 2.9 | 37.8 | 4.6 | 35.0 |
72+
| YOLOv8s-Seg | | 36.8 | 4.2 | 34.0 |
73+
| RF-DETR Seg-Preview@432 | | | 5.6 | 44.3 |
74+
| YOLO11m-Seg | 6.3 | 41.5 | 6.9 | 38.5 |
75+
| YOLOv8m-Seg | | 40.8 | 7.0 | 37.3 |
76+
| YOLO11l-Seg | 7.8 | 42.9 | 8.3 | 39.5 |
77+
| YOLOv8l-Seg | | 42.6 | 9.7 | 39.0 |
78+
| YOLO11x-Seg | 15.8 | 43.8 | 13.7 | 40.1 |
79+
| YOLOv8x-Seg | | 43.4 | 14.0 | 39.5 |
80+
81+
For more information on measuring end-to-end latency for models, see our open source [Single Artifact Benchmarking tool](https://github.com/roboflow/single_artifact_benchmarking).
82+
5483
## Installation
5584

5685
To install RF-DETR, install the `rfdetr` package in a [**Python>=3.9**](https://www.python.org/) environment with `pip`:
@@ -102,6 +131,8 @@ annotated_image = sv.BoxAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annot
102131
annotated_image = sv.LabelAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections, labels)
103132
```
104133

134+
To use segmentation, use the `rfdetr-seg-preview` model ID. This model will return segmentation masks from a RF-DETR-Seg (Preview) model trained on the Microsoft COCO dataset.
135+
105136
## Predict
106137

107138
You can also use the .predict method to perform inference during local development. The `.predict()` method accepts various input formats, including file paths, PIL images, NumPy arrays, and torch tensors. Please ensure inputs use RGB channel order. For `torch.Tensor` inputs specifically, they must have a shape of `(3, H, W)` with values normalized to the `[0..1)` range. If you don't plan to modify the image or batch size dynamically at runtime, you can also use `.optimize_for_inference()` to get up to 2x end-to-end speedup, depending on platform.
@@ -140,7 +171,7 @@ sv.plot_image(annotated_image)
140171

141172
You can fine-tune an RF-DETR Nano, Small, Medium, and Base model with a custom dataset using the `rfdetr` Python package.
142173

143-
[Read our training tutorial to get started](https://rfdetr.roboflow.com/learn/train/)
174+
[Learn how to train an RF-DETR model.](https://rfdetr.roboflow.com/learn/train/)
144175

145176
## Documentation
146177

docs/index.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,36 @@
11
---
22
hide:
3-
- toc
43
- navigation
54
---
65

7-
# RF-DETR: SOTA Real-Time Object Detection Model
6+
# RF-DETR: SOTA Real-Time Detection and Segmentation Model
87

98
## Introduction
109

11-
RF-DETR is a real-time, transformer-based object detection model architecture developed by Roboflow and released under the Apache 2.0 license.
10+
RF-DETR is a real-time, transformer-based object detection and instance segmentation model architecture developed by Roboflow and released under the Apache 2.0 license.
1211

13-
RF-DETR is the first real-time model to exceed 60 AP on the [Microsoft COCO benchmark](https://cocodataset.org/#home) alongside competitive performance at base sizes. It also achieves state-of-the-art performance on [RF100-VL](https://github.com/roboflow/rf100-vl), an object detection benchmark that measures model domain adaptability to real world problems. RF-DETR is fastest and most accurate for its size when compared current real-time objection models.
12+
RF-DETR is the first real-time model to exceed 60 AP on the [Microsoft COCO object detection benchmark](https://cocodataset.org/#home) alongside competitive performance at base sizes. It also achieves state-of-the-art performance on [RF100-VL](https://github.com/roboflow/rf100-vl), an object detection benchmark that measures model domain adaptability to real world problems. RF-DETR is fastest and most accurate for its size when compared current real-time objection models.
13+
14+
On image segmentation, RF-DETR Seg (Preview) is 3x faster and more accurate than the largest YOLO when evaluated on the Microsoft COCO Segmentation benchmark, defining a new real-time state-of-the-art for the industry-standard benchmark in segmentation model evaluation.
1415

1516
RF-DETR is small enough to run on the edge using [Inference](https://github.com/roboflow/inference), making it an ideal model for deployments that need both strong accuracy and real-time performance.
1617

17-
## Results
18+
## Benchmark Results
19+
20+
### Object Detection
1821

1922
We validated the performance of RF-DETR on both Microsoft COCO and the RF100-VL benchmarks.
2023

2124
[See our full benchmarks.](learn/benchmarks/)
2225

2326
<img src="https://media.roboflow.com/rfdetr/pareto1.png" style="max-height: 50rem" />
2427

28+
### Instance Segmentation
29+
30+
We benchmarked RF-DETR on the Microsoft COCO dataset for segmentation. Our results are below.
31+
32+
![rf-detr-coco-rf100-vl-9](https://media.roboflow.com/rfdetr/pareto_seg.png)
33+
2534
## 💻 Install
2635

2736
You can install and use `rfdetr` in a

docs/learn/deploy.md

Lines changed: 76 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,33 @@ Deploying to Roboflow allows you to create multi-step computer vision applicatio
66

77
To deploy your model to Roboflow, run:
88

9-
```python
10-
from rfdetr import RFDETRNano
11-
12-
x = RFDETRNano(pretrain_weights="<path/to/pretrain/weights/dir>")
13-
x.deploy_to_roboflow(
14-
workspace="<your-workspace>",
15-
project_id="<your-project-id>",
16-
version=1,
17-
api_key="<YOUR_API_KEY>"
18-
)
19-
```
9+
=== "Object Detection"
10+
11+
```python
12+
from rfdetr import RFDETRNano
13+
14+
x = RFDETRNano(pretrain_weights="<path/to/pretrain/weights/dir>")
15+
x.deploy_to_roboflow(
16+
workspace="<your-workspace>",
17+
project_id="<your-project-id>",
18+
version=1,
19+
api_key="<YOUR_API_KEY>"
20+
)
21+
```
22+
23+
=== "Image Segmentation"
24+
25+
```python
26+
from rfdetr import RFDETRSegPreview
27+
28+
x = RFDETRSegPreview(pretrain_weights="<path/to/pretrain/weights/dir>")
29+
x.deploy_to_roboflow(
30+
workspace="<your-workspace>",
31+
project_id="<your-project-id>",
32+
version=1,
33+
api_key="<YOUR_API_KEY>"
34+
)
35+
```
2036

2137
Above, set your Roboflow Workspace ID, the ID of the project to which you want to upload your model, and your Roboflow API key.
2238

@@ -25,31 +41,62 @@ Above, set your Roboflow Workspace ID, the ID of the project to which you want t
2541

2642
You can then run your model with Roboflow Inference:
2743

28-
```python
29-
import os
30-
import supervision as sv
31-
from inference import get_model
32-
from PIL import Image
33-
from io import BytesIO
34-
import requests
3544

36-
url = "https://media.roboflow.com/dog.jpeg"
37-
image = Image.open(BytesIO(requests.get(url).content))
45+
=== "Object Detection"
3846

39-
model = get_model("rfdetr-base") # replace with your Roboflow model ID
47+
```python
48+
import os
49+
import supervision as sv
50+
from inference import get_model
51+
from PIL import Image
52+
from io import BytesIO
53+
import requests
4054

41-
predictions = model.infer(image, confidence=0.5)[0]
55+
url = "https://media.roboflow.com/dog.jpeg"
56+
image = Image.open(BytesIO(requests.get(url).content))
4257

43-
detections = sv.Detections.from_inference(predictions)
58+
model = get_model("rfdetr-base") # replace with your Roboflow model ID
4459

45-
labels = [prediction.class_name for prediction in predictions.predictions]
60+
predictions = model.infer(image, confidence=0.5)[0]
4661

47-
annotated_image = image.copy()
48-
annotated_image = sv.BoxAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections)
49-
annotated_image = sv.LabelAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections, labels)
62+
detections = sv.Detections.from_inference(predictions)
5063

51-
sv.plot_image(annotated_image)
52-
```
64+
labels = [prediction.class_name for prediction in predictions.predictions]
65+
66+
annotated_image = image.copy()
67+
annotated_image = sv.BoxAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections)
68+
annotated_image = sv.LabelAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections, labels)
69+
70+
sv.plot_image(annotated_image)
71+
```
72+
73+
=== "Image Segmentation"
74+
75+
```python
76+
import os
77+
import supervision as sv
78+
from inference import get_model
79+
from PIL import Image
80+
from io import BytesIO
81+
import requests
82+
83+
url = "https://media.roboflow.com/dog.jpeg"
84+
image = Image.open(BytesIO(requests.get(url).content))
85+
86+
model = get_model("rfdetr-seg-preview") # replace with your Roboflow model ID
87+
88+
predictions = model.infer(image, confidence=0.5)[0]
89+
90+
detections = sv.Detections.from_inference(predictions)
91+
92+
labels = [prediction.class_name for prediction in predictions.predictions]
93+
94+
annotated_image = image.copy()
95+
annotated_image = sv.MaskAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections)
96+
annotated_image = sv.LabelAnnotator(color=sv.ColorPalette.ROBOFLOW).annotate(annotated_image, detections, labels)
97+
98+
sv.plot_image(annotated_image)
99+
```
53100

54101
Above, replace `rfdetr-base` with the your Roboflow model ID. You can find this ID from the "Models" list in your Roboflow dashboard:
55102

0 commit comments

Comments
 (0)