RF-DETR Segmentation
RF-DETR-Seg: real-time instance segmentation transformer (Roboflow, Apache-2.0, released Jan 2026). DINOv2 backbone + deformable DETR decoder with instance segmentation head. SOTA on COCO among real-time models.
RF-DETR: Real-Time Detection Transformer for Instance Segmentation
Summary
Introduction
RF-DETR is an end-to-end instance segmentation model that combines ideas from LW-DETR and Deformable DETR: a DINOv2-with-registers style ViT backbone (with an RF-DETR windowing pattern for efficient attention), a multi-scale projector between encoder and decoder, and a multi-scale deformable DETR decoder extended with an instance-segmentation head.
Key Architectural Details:
- Backbone: DINOv2-with-registers style ViT with RF-DETR windowed / full attention alternation.
- Multi-scale fusion: RF-DETR multi-scale projector (C2f-style blocks in the LW-DETR lineage) to aggregate multi-level backbone features before the decoder.
- Decoder: Deformable DETR-style decoder with multi-scale deformable cross-attention; segmentation checkpoints add mask prediction on top of box/class outputs.
- Queries: DETR-style object queries with bipartite matching and auxiliary decoder losses.
Training Details:
- Segmentation losses: mask prediction losses (e.g. focal / dice style terms as configured) in addition to box and classification objectives, with auxiliary decoder supervision.
- Group DETR: parallel decoder copies during training for faster convergence.
- NAS (family-level): weight-sharing search over accuracy–latency knobs as in the RF-DETR paper, specialized to the target dataset distribution.
Parameters
Inputs
- input - (image -.png|.jpg|.jpeg): The input image containing objects to segment.
- threshold - (number-float, optional): Confidence score threshold for instance segmentation prediction. Default is 0.5.
Output
- output - (image -.png): The output image with detected instance segmentation masks, bounding boxes, class labels, and confidence scores overlaid on top of the original input.
Examples
| input | threshold | output |
|---|---|---|
![]() | 0.5 | ![]() |
Usage for developers
Please find below the details to track the information and access the code for processing the model on our platform.
Requirements
- Python 3.10 or newer
- Git LFS for the model checkpoints
- A CUDA-capable GPU is optional
Fetch LFS objects if the repository was cloned without them, then install the dependencies:
git lfs pull
pip install -r requirements.txt
Run the demo
python demo.py
Code based on AIOZ structure
import os
import tempfile
from pathlib import Path
from typing import Any, Literal, Union
import numpy as np
import torch
from PIL import Image
from transformers import RfDetrForInstanceSegmentation, RfDetrImageProcessor
...
def do_ai_task(
input: Union[str, Path],
model_storage_directory: Union[str, Path],
device: Literal["cpu", "cuda", "gpu"] = "cpu",
threshold: float = 0.5,
*args,
**kwargs,
) -> Any:
"""Define AI task: load model, pre-process, infer, post-process, overlay masks"""
device_str = "cuda" if device in ["cuda", "gpu"] and torch.cuda.is_available() else "cpu"
model_dir = os.path.abspath(str(model_storage_directory))
processor = RfDetrImageProcessor.from_pretrained(model_dir, local_files_only=True)
model = RfDetrForInstanceSegmentation.from_pretrained(model_dir, local_files_only=True).to(device_str)
model.eval()
image = Image.open(str(input)).convert("RGB")
inputs = processor(images=image, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model(**inputs)
results = processor.post_process_instance_segmentation(
outputs,
threshold=threshold,
target_sizes=[image.size[::-1]],
)[0]
# Create mask overlay and save to temporary file
blended_image = show_masks_on_image(image, results, model.config.id2label)
fd, fp = tempfile.mkstemp(suffix=".png")
os.close(fd)
blended_image.save(fp)
return fp
Reference
This repository utilizes the RF-DETR model developed by Roboflow:
- Paper: RF-DETR: Neural Architecture Search for Real-Time Detection Transformers (arXiv:2511.09554)
- Model Source: Roboflow/rf-detr-segmentation on HuggingFace
License
We respect and comply with the terms of the author's Apache-2.0 license cited in the Reference section.
Citation
@misc{robinson2026rfdetrneuralarchitecturesearch,
title={RF-DETR: Neural Architecture Search for Real-Time Detection Transformers},
author={Isaac Robinson and Peter Robicheaux and Matvei Popov and Deva Ramanan and Neehar Peri},
year={2026},
eprint={2511.09554},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://huggingface.co/papers/2511.09554},
}

