> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deploy/supported-models/rf-detr.md).

# RF-DETR

## RF-DETR Object Detection

RF-DETR is Roboflow's transformer-based real-time detection model. Run inference against COCO-pretrained object detection checkpoints through the [Serverless Hosted API](/deploy/serverless-hosted-api-v2.md), or self-host using [Roboflow Inference](https://inference.roboflow.com/).

### Code sample

The steps below run RF-DETR through the [Serverless Hosted API](/deploy/serverless-hosted-api-v2.md) and visualize results with [supervision](https://supervision.roboflow.com/).

{% stepper %}
{% step %}
**Get your API Key**

Create a Roboflow account, find your key on the [Roboflow API settings page](https://app.roboflow.com/settings/api) and make it available to your shell:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}
**Install the dependencies**

These two packages call the model and draw its results:

```bash
pip install inference-sdk supervision
```

{% endstep %}

{% step %}
**Run the model**

Run `rfdetr-small` on a sample image and annotate boxes and labels:

```python
import os
import cv2
import numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

image_url = "https://media.roboflow.com/quickstart/traffic.jpg"
content = requests.get(image_url).content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="rfdetr-small")

detections = sv.Detections.from_inference(result)

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)

cv2.imwrite("traffic-annotated.png", annotated)
```

<figure><img src="/files/1IzLvvLBBSUAXad1685k" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Set `api_url` to match your deployment target:

* `https://serverless.roboflow.com` for the Serverless Hosted API.
* `http://localhost:9001` for a local [Inference](https://inference.roboflow.com/) server.
* Your [Dedicated Deployment](/deploy/dedicated-deployments.md) URL for a private endpoint.
  {% endhint %}

### Pretrained models and benchmarks

Pass any of these aliases as the `model_id` when running inference. The SDK resolves each alias to the underlying Roboflow project version.

<table data-search="false"><thead><tr><th>Alias</th><th>Input Size</th><th>mAP50-95</th><th>ONNX latency (ms)*</th><th>TensorRT FP16 (ms)*</th></tr></thead><tbody><tr><td><code>rfdetr-nano</code></td><td>384x384</td><td>48.4</td><td>9.7</td><td>6.2</td></tr><tr><td><code>rfdetr-small</code></td><td>512x512</td><td>53.0</td><td>12.9</td><td>8.3</td></tr><tr><td><code>rfdetr-medium</code></td><td>576x576</td><td>54.7</td><td>16.3</td><td>9.5</td></tr><tr><td><code>rfdetr-large</code></td><td>704x704</td><td>56.5</td><td>25.6</td><td>11.6</td></tr><tr><td><code>rfdetr-xlarge</code></td><td>700x700</td><td>58.6</td><td>41.6</td><td>14.9</td></tr><tr><td><code>rfdetr-2xlarge</code></td><td>880x880</td><td>60.1</td><td>53.4</td><td>21.7</td></tr></tbody></table>

## RF-DETR Instance Segmentation

RF-DETR also provides instance segmentation checkpoints that predict masks alongside boxes. Run them through the [Serverless Hosted API](/deploy/serverless-hosted-api-v2.md), or self-host using [Roboflow Inference](https://inference.roboflow.com/).

### Code sample

Set your API key and install the dependencies as shown above, then run a segmentation checkpoint and draw its masks:

```python
import os
import cv2
import numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

image_url = "https://media.roboflow.com/quickstart/traffic.jpg"
content = requests.get(image_url).content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="rfdetr-seg-preview")

detections = sv.Detections.from_inference(result)

annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)

cv2.imwrite("traffic-annotated.png", annotated)
```

<figure><img src="/files/KqjVgQqtVxDOxSDoQMff" alt=""><figcaption></figcaption></figure>

### Pretrained models and benchmarks

Pass any of these aliases as the `model_id` when running inference. The SDK resolves each alias to the underlying Roboflow project version. Figures are mask mAP on COCO `val`.

<table data-search="false"><thead><tr><th>Alias</th><th>Input Size</th><th>Mask mAP50-95</th><th>ONNX latency (ms)*</th><th>TensorRT FP16 (ms)*</th></tr></thead><tbody><tr><td><code>rfdetr-seg-nano</code></td><td>312x312</td><td>40.3</td><td>15.8</td><td>10.5</td></tr><tr><td><code>rfdetr-seg-small</code></td><td>384x384</td><td>43.1</td><td>19.3</td><td>11.9</td></tr><tr><td><code>rfdetr-seg-medium</code></td><td>432x432</td><td>45.3</td><td>23.9</td><td>14.1</td></tr><tr><td><code>rfdetr-seg-large</code></td><td>504x504</td><td>47.1</td><td>30.1</td><td>15.4</td></tr><tr><td><code>rfdetr-seg-xlarge</code></td><td>624x624</td><td>48.8</td><td>51.2</td><td>19.1</td></tr><tr><td><code>rfdetr-seg-2xlarge</code></td><td>768x768</td><td>49.9</td><td>89.6</td><td>25.6</td></tr></tbody></table>

***

\* Latency is measured with [Roboflow Inference](https://inference.roboflow.com/) on 1x NVIDIA L4, batch size 1, mean of 1,000 inferences (100 warmup). The default `inference-gpu` install runs ONNX on the CUDA execution provider; adding the `inference-models[trt10]` extra selects a prebuilt TensorRT FP16 engine automatically. FP16 matches FP32 accuracy within 0.2 mAP on COCO `val2017`. Accuracy is the published COCO `val` spec (see the [RF-DETR announcement](https://blog.roboflow.com/rf-detr/)).
