Skip to main content
1

Install RF-DETR

Install the rfdetr package in a Python >= 3.10 environment.
pip install rfdetr
2

Run detection

Load a pre-trained detection model and run inference on an image.
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.data["source_image"], detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections, labels)
Replace RFDETRMedium with any other class from the model variants reference to use a different size.
3

Run segmentation

Load a pre-trained segmentation model and run inference on an image.
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.data["source_image"], detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections, labels)
Replace RFDETRSegMedium with any other segmentation class from the model variants reference to use a different size.
4

Fine-tune on your dataset

Fine-tune a detection or segmentation model on your own labeled dataset.
from rfdetr import RFDETRMedium

model = RFDETRMedium()

model.train(
    dataset_dir="<DATASET_PATH>",
    epochs=100,
    batch_size=4,
    grad_accum_steps=4,
    lr=1e-4,
    output_dir="<OUTPUT_PATH>",
)
The default configuration uses batch_size=4 and grad_accum_steps=4, giving an effective batch size of 16. Adjust both values together to maintain this total across different GPU memory sizes — for example, use batch_size=16, grad_accum_steps=1 on an A100, or batch_size=2, grad_accum_steps=8 on a smaller 12 GB GPU.
RF-DETR automatically detects whether your dataset is in COCO or YOLO format. See the dataset formats guide for details.

Next steps

Run detection

Learn all the options for running detection models on images, video, and streams.

Run segmentation

Run segmentation models for pixel-level instance predictions.

Train overview

Full guide to fine-tuning RF-DETR on a custom dataset.

Model variants

All available model sizes with benchmarks and class names.

Build docs developers (and LLMs) love