Metadata-Version: 2.4
Name: rfdetr-plus
Version: 1.3.0
Summary: RF-DETR+ Extension Package
Author-email: "Roboflow, Inc" <develop@roboflow.com>
License-Expression: LicenseRef-PML-1.0
Project-URL: Homepage, https://github.com/roboflow/rf-detr-plus
Keywords: machine-learning,deep-learning,vision,ML,DL,AI,DETR,RF-DETR,Roboflow
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Typing :: Typed
Classifier: Operating System :: POSIX
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: rfdetr<2,>=1.12.0
Requires-Dist: timm<2,>=1.0.27
Provides-Extra: onnx
Requires-Dist: rfdetr[onnx]>=1.12.0; extra == "onnx"
Requires-Dist: torch>=2.11; extra == "onnx"
Requires-Dist: onnx<2,>=1.19; extra == "onnx"
Requires-Dist: onnxruntime<2,>=1.23.2; extra == "onnx"
Dynamic: license-file

# RF-DETR+: Platform Detection Models for RF-DETR

[![version](https://badge.fury.io/py/rfdetr-plus.svg)](https://badge.fury.io/py/rfdetr-plus) [![downloads](https://img.shields.io/pypi/dm/rfdetr-plus)](https://pypistats.org/packages/rfdetr-plus) [![python-version](https://img.shields.io/pypi/pyversions/rfdetr-plus)](https://badge.fury.io/py/rfdetr-plus) [![license](https://img.shields.io/badge/license-PML--1.0-blue)](https://github.com/roboflow/rf-detr-plus/blob/main/LICENSE)

[![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) [![Papers with Code leaderboard](https://paperswithcode.co/api/v1/papers/2511.09554/leaderboard-badge.svg?eval=821&live=1)](https://paperswithcode.co/api/v1/papers/2511.09554/leaderboard-badge-link?eval=821)

RF-DETR is the core package in the ecosystem. It provides the full training and inference stack, the {Nano, Small, Medium, Large} model lineup, and the APIs most users build on. RF-DETR+ is an extension package for [RF-DETR](https://github.com/roboflow/rf-detr) that adds the **XLarge** and **2XLarge** detection models for maximum accuracy and the **Atto**, **Femto** and **Pico** detection models for the lowest latency.

RF-DETR+ models use a DINOv2 vision transformer backbone at higher resolutions and larger feature dimensions than the core RF-DETR lineup, pushing state-of-the-art accuracy on [Microsoft COCO](https://cocodataset.org/#home) and [RF100-VL](https://github.com/roboflow/rf100-vl) while retaining real-time inference speeds. Atto, Femto and Pico instead use Meta's [Perception Encoder](https://arxiv.org/abs/2504.13181) PE-Core-T backbone, with architectures selected by neural architecture search, to run in 1-2 ms on a T4. Use RF-DETR for the standard model set and RF-DETR+ when you need the highest-accuracy or the fastest variants.

## Install

Install RF-DETR+ in a [**Python>=3.10**](https://www.python.org/) environment with `pip`. This will also install [`rfdetr`](https://github.com/roboflow/rf-detr) as a dependency, which provides the core APIs and model definitions.

```bash
pip install rfdetr-plus
```

<details>
<summary>Install from source</summary>

<br>

```bash
pip install git+https://github.com/roboflow/rf-detr-plus.git
```

</details>

## Benchmarks

RF-DETR+ XLarge and 2XLarge sit at the top of the RF-DETR accuracy/latency curve, delivering the highest COCO AP scores in the family, while Atto, Femto and Pico extend it below Nano. All latency numbers were measured on an NVIDIA T4 using TensorRT, FP16, and batch size 1.

|  Size  |      Class      | 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 |                      Package / License                       |
| :----: | :-------------: | :------------------: | :---------------------: | :---------------------: | :------------------------: | :----------: | :--------: | :--------: | :----------------------------------------------------------: |
|  ⭐ A  |  `RFDETRAtto`   |         49.4         |          30.5           |          78.2           |            48.3            |     1.0      |    7.4     |  380x380   |              `rfdetr_plus` / [PML 1.0](LICENSE)              |
|  ⭐ F  |  `RFDETRFemto`  |         55.9         |          37.8           |          82.5           |            53.8            |     1.4      |    7.9     |  384x384   |              `rfdetr_plus` / [PML 1.0](LICENSE)              |
|  ⭐ P  |  `RFDETRPico`   |         60.2         |          41.6           |          84.1           |            56.0            |     1.7      |    8.4     |  560x560   |              `rfdetr_plus` / [PML 1.0](LICENSE)              |
|   N    |  `RFDETRNano`   |         67.6         |          48.4           |          85.0           |            57.7            |     2.3      |    30.5    |  384x384   | [`rfdetr`](https://github.com/roboflow/rf-detr) / Apache 2.0 |
|   S    |  `RFDETRSmall`  |         72.1         |          53.0           |          86.7           |            60.2            |     3.5      |    32.1    |  512x512   | [`rfdetr`](https://github.com/roboflow/rf-detr) / Apache 2.0 |
|   M    | `RFDETRMedium`  |         73.6         |          54.7           |          87.4           |            61.2            |     4.4      |    33.7    |  576x576   | [`rfdetr`](https://github.com/roboflow/rf-detr) / Apache 2.0 |
|   L    |  `RFDETRLarge`  |         75.1         |          56.5           |          88.2           |            62.2            |     6.8      |    33.9    |  704x704   | [`rfdetr`](https://github.com/roboflow/rf-detr) / Apache 2.0 |
| ⭐ XL  | `RFDETRXLarge`  |         77.4         |          58.6           |          88.5           |            62.9            |     11.5     |   126.4    |  700x700   |              `rfdetr_plus` / [PML 1.0](LICENSE)              |
| ⭐ 2XL | `RFDETR2XLarge` |         78.5         |          60.1           |          89.0           |            63.2            |     17.2     |   126.9    |  880x880   |              `rfdetr_plus` / [PML 1.0](LICENSE)              |

## Run Models

Install RF-DETR+ to use XL and 2XL models alongside the core RF-DETR lineup:

```bash
pip install rfdetr_plus
```

RF-DETR+ models require you to accept the Platform Model License before use. Once accepted, usage mirrors the standard RF-DETR API -- you import the models from `rfdetr_plus` and keep using the `rfdetr` utilities:

```python
import requests
import supervision as sv
from PIL import Image
from rfdetr_plus import RFDETRXLarge
from rfdetr.assets.coco_classes import COCO_CLASSES

model = RFDETRXLarge(accept_platform_model_license=True)

image = Image.open(requests.get("https://media.roboflow.com/dog.jpg", stream=True).raw)
detections = model.predict(image, threshold=0.5)

labels = [f"{COCO_CLASSES[class_id]}" for class_id in detections.class_id]

annotated_image = sv.BoxAnnotator().annotate(image, detections)
annotated_image = sv.LabelAnnotator().annotate(annotated_image, detections, labels)
```

### Train Models

RF-DETR+ models support fine-tuning with the same training API as core RF-DETR. You can train on your own dataset or use datasets from [Roboflow Universe](https://universe.roboflow.com/). Training needs the training extras of the core package, so install them first with `pip install "rfdetr[train]"`.

```python
from rfdetr_plus import RFDETRXLarge

model = RFDETRXLarge(accept_platform_model_license=True)
model.train(dataset_dir="path/to/dataset", epochs=50, lr=1e-4)
```

### Export Atto, Femto or Pico for CPU

Install `pip install "rfdetr-plus[onnx]"`. The compact ONNX export uses batch size one at the detector's configured resolution and targets the standard encoder and decoder layout for each size. It derives its weights from the loaded model and computes activation scales at inference time.

```python
from rfdetr import RFDETRInference, from_checkpoint
from rfdetr_plus import RFDETRAtto

# The released COCO Atto fits this optional 8 MB storage budget.
pretrained = RFDETRAtto(device="cpu")
pretrained.export_cpu_onnx("output/pretrained", size_limit_bytes=8_000_000)

trained = from_checkpoint("checkpoint_best_total.pth", device="cpu")
artifact = trained.export_cpu_onnx("output/finetuned")
predictions = RFDETRInference(artifact, device="cpu").predict("image.jpg")
```

The optional `size_limit_bytes` checks the complete uncompressed file before publishing the artifact. The call raises `ValueError` if the file reaches or exceeds that limit. The reference Femto and Pico CPU exports are 11.77 MB and 13.10 MB respectively.

The encoder uses fused rotary and attention operators. Every size quantizes the 36 encoder projections (`qkv`, `proj` and `fc1` of all twelve blocks) to dynamic INT8, and each size adds its own recipe on top:

- Atto: `fc2` of encoder blocks 6-11 also uses dynamic INT8, the 1x1 projector convolutions become float NHWC matrix multiplications, and the remaining large filters are stored as scaled INT8.
- Femto: `linear2` of decoder `layers.1` also uses dynamic INT8, and the remaining large filters are stored in FP16.
- Pico: `linear1` of decoder `layers.1` also uses dynamic INT8, the 1x1 projector convolutions become float NHWC matrix multiplications, and the remaining large filters are stored in FP16.

The export fails before tracing for any other size, for a non-PE-Core-T encoder, and for Femto or Pico with fewer than two decoder layers. The file uses ONNX opset 23, so run it with `onnxruntime>=1.23.2`, the tested floor.

This differs from the base `model.export(format="onnx", quantization="int8")`, which writes a static QDQ model with INT8 weights and activations and requires `calibration_data`. The compact export needs no calibration data. `output_name` follows the base full-stem semantics: the file is `{output_name}.onnx`, and the default is the model's size name plus `-cpu`, such as `rfdetr-atto-cpu.onnx`. Compare the compact export with `model.export(format="onnx")` on your validation images and target CPU to measure the accuracy and latency trade-off.

## Documentation

Visit the [RF-DETR documentation website](https://rfdetr.roboflow.com) to learn more about training, export, deployment, and the full model lineup.

## License

RF-DETR+ code and model checkpoints are licensed under the Platform Model License 1.0 (PML-1.0). See [`LICENSE`](LICENSE) for details. These models require a [Roboflow](https://roboflow.com) account to run and fine-tune.

The core RF-DETR models (Nano through Large) are available under the Apache License 2.0 in the [`rfdetr`](https://github.com/roboflow/rf-detr) package.

## Acknowledgements

Our work is built upon [LW-DETR](https://arxiv.org/pdf/2406.03459), [DINOv2](https://arxiv.org/pdf/2304.07193), and [Deformable DETR](https://arxiv.org/pdf/2010.04159). Thanks to their authors for their excellent work!

## Citation

If you find our work helpful for your research, please consider citing the following BibTeX entry.

```bibtex
@misc{rf-detr,
    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={2025},
    eprint={2511.09554},
    archivePrefix={arXiv},
    primaryClass={cs.CV},
    url={https://arxiv.org/abs/2511.09554},
}
```

## Contribute

We welcome and appreciate all contributions! If you notice any issues or bugs, have questions, or would like to suggest new features, please [open an issue](https://github.com/roboflow/rf-detr-plus/issues/new) or pull request. By sharing your ideas and improvements, you help make RF-DETR better for everyone.

<p align="center">
    <a href="https://youtube.com/roboflow"><img src="https://media.roboflow.com/notebooks/template/icons/purple/youtube.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949634652" width="3%"/></a>
    <img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
    <a href="https://roboflow.com"><img src="https://media.roboflow.com/notebooks/template/icons/purple/roboflow-app.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949746649" width="3%"/></a>
    <img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
    <a href="https://www.linkedin.com/company/roboflow-ai/"><img src="https://media.roboflow.com/notebooks/template/icons/purple/linkedin.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949633691" width="3%"/></a>
    <img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
    <a href="https://docs.roboflow.com"><img src="https://media.roboflow.com/notebooks/template/icons/purple/knowledge.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949634511" width="3%"/></a>
    <img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
    <a href="https://discuss.roboflow.com"><img src="https://media.roboflow.com/notebooks/template/icons/purple/forum.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949633584" width="3%"/></a>
    <img src="https://raw.githubusercontent.com/ultralytics/assets/main/social/logo-transparent.png" width="3%"/>
    <a href="https://blog.roboflow.com"><img src="https://media.roboflow.com/notebooks/template/icons/purple/blog.png?ik-sdk-version=javascript-1.4.3&updatedAt=1672949633605" width="3%"/></a>
</p>
