# roboflow/rf-detr architecture

> Architecture diagram of the GitHub repository roboflow/rf-detr, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roboflow/rf-detr
- Repository: https://github.com/roboflow/rf-detr

## Overview

RF-DETR is a transformer-based computer-vision package for object detection, instance segmentation, and keypoint detection. A user supplies a model and images to the inference facade, which prepares batches, runs the model, and decodes predictions; users can also train models from annotated datasets and export models for supported runtimes. The graph preserves training, evaluation, and deployment as distinct capabilities. Relationships are limited to README statements and references in the supplied SOURCE INDEX; unsampled backend details are represented at their enclosing directory.

Main entry points: [`src/rfdetr/inference.py`](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/inference.py) (Inference facade), [`src/rfdetr/models/lwdetr.py`](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/lwdetr.py) (LW-DETR model), [`src/rfdetr/training/module_model.py`](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/module_model.py) (Training module), [`src/rfdetr/detr.py`](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/detr.py) (Model API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Data preparation"]
  node_dataset["Dataset formats"]
  node_coco["COCO dataset<br/>[coco.py]"]
end

subgraph group_model["Model and inference"]
  node_configs["Model configuration<br/>[config.py]"]
  node_facade["Model API<br/>[detr.py]"]
  node_inference["Inference facade<br/>[inference.py]"]
  node_prediction["Prediction pipeline<br/>[core.py]"]
  node_streams["Batch scheduling<br/>[pipelines.py]"]
  node_architecture["LW-DETR model<br/>[lwdetr.py]"]
  node_backbone["DINOv2 backbone"]
  node_transformer["Transformer<br/>[transformer.py]"]
  node_postprocess["Prediction postprocess<br/>[postprocess.py]"]
  node_weights["Model weights<br/>[weights.py]"]
end

subgraph group_train["Training and evaluation"]
  node_training["Training module<br/>[module_model.py]"]
  node_trainer["Training orchestration<br/>[trainer.py]"]
  node_evaluation["COCO evaluation<br/>[coco_eval.py]"]
end

subgraph group_deploy["Export and runtimes"]
  node_export["Model export"]
  node_metadata["Export metadata<br/>[metadata.py]"]
  node_adapters["Runtime adapters<br/>[adapters.py]"]
  node_runtimes["Backend inference"]
end

node_user(("User"))

node_user -->|"uses model API"| node_facade
node_facade -->|"configures model"| node_configs
node_facade -->|"creates inference"| node_inference
node_inference -->|"runs prediction"| node_prediction
node_prediction -->|"schedules batches"| node_streams
node_inference -->|"loads native model"| node_architecture
node_architecture -->|"uses backbone"| node_backbone
node_architecture -->|"uses transformer"| node_transformer
node_architecture -->|"configures postprocess"| node_postprocess
node_inference -->|"loads weights"| node_weights
node_user -->|"provides data"| node_dataset
node_dataset -->|"supports COCO"| node_coco
node_user -.->|"starts training"| node_trainer
node_trainer -.->|"orchestrates training"| node_training
node_training -->|"loads dataset"| node_coco
node_training -->|"trains model"| node_architecture
node_training -->|"registers evaluation"| node_evaluation
node_user -.->|"exports model"| node_export
node_export -->|"writes metadata"| node_metadata
node_inference -->|"loads exported runtime"| node_adapters
node_adapters -->|"dispatches backend"| node_runtimes
node_runtimes -->|"reads metadata"| node_metadata

click node_dataset "https://github.com/roboflow/rf-detr/tree/develop/src/rfdetr/datasets"
click node_coco "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/datasets/coco.py"
click node_configs "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/config.py"
click node_facade "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/detr.py"
click node_inference "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/inference.py"
click node_prediction "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/_prediction/core.py"
click node_streams "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/_prediction/pipelines.py"
click node_architecture "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/lwdetr.py"
click node_backbone "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/backbone/dinov2_with_windowed_attn.py"
click node_transformer "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/transformer.py"
click node_postprocess "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/postprocess.py"
click node_weights "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/weights.py"
click node_training "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/module_model.py"
click node_trainer "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/trainer.py"
click node_evaluation "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/callbacks/coco_eval.py"
click node_export "https://github.com/roboflow/rf-detr/tree/develop/src/rfdetr/export"
click node_metadata "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/export/_runtime/metadata.py"
click node_adapters "https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/export/_runtime/adapters.py"
click node_runtimes "https://github.com/roboflow/rf-detr/tree/develop/src/rfdetr/export"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dataset,node_coco,node_user toneBlue
class node_configs,node_facade,node_inference,node_prediction,node_streams,node_architecture,node_backbone,node_transformer,node_postprocess,node_weights toneAmber
class node_training,node_trainer,node_evaluation toneMint
class node_export,node_metadata,node_adapters,node_runtimes toneRose
```

## Components

### Data preparation

- [Dataset formats](https://github.com/roboflow/rf-detr/tree/develop/src/rfdetr/datasets): `src/rfdetr/datasets`
- [COCO dataset](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/datasets/coco.py): `src/rfdetr/datasets/coco.py`

### Model and inference

- [Model configuration](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/config.py): `src/rfdetr/config.py`
- [Model API](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/detr.py): `src/rfdetr/detr.py`
- [Inference facade](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/inference.py): `src/rfdetr/inference.py`
- [Prediction pipeline](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/_prediction/core.py): `src/rfdetr/_prediction/core.py`
- [Batch scheduling](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/_prediction/pipelines.py): `src/rfdetr/_prediction/pipelines.py`
- [LW-DETR model](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/lwdetr.py): `src/rfdetr/models/lwdetr.py`
- [DINOv2 backbone](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/backbone/dinov2_with_windowed_attn.py): `src/rfdetr/models/backbone/dinov2_with_windowed_attn.py`
- [Transformer](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/transformer.py): `src/rfdetr/models/transformer.py`
- [Prediction postprocess](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/postprocess.py): `src/rfdetr/models/postprocess.py`
- [Model weights](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/models/weights.py): `src/rfdetr/models/weights.py`

### Training and evaluation

- [Training module](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/module_model.py): `src/rfdetr/training/module_model.py`
- [Training orchestration](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/trainer.py): `src/rfdetr/training/trainer.py`
- [COCO evaluation](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/training/callbacks/coco_eval.py): `src/rfdetr/training/callbacks/coco_eval.py`

### Export and runtimes

- [Model export](https://github.com/roboflow/rf-detr/tree/develop/src/rfdetr/export): `src/rfdetr/export`
- [Export metadata](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/export/_runtime/metadata.py): `src/rfdetr/export/_runtime/metadata.py`
- [Runtime adapters](https://github.com/roboflow/rf-detr/blob/develop/src/rfdetr/export/_runtime/adapters.py): `src/rfdetr/export/_runtime/adapters.py`
- [Backend inference](https://github.com/roboflow/rf-detr/tree/develop/src/rfdetr/export): `src/rfdetr/export`

### Other components

- **User**

## Connections

- User → Model API: uses model API (evidence: `README.md`)
- Model API → Model configuration: configures model (evidence: `src/rfdetr/detr.py`)
- Model API → Inference facade: creates inference (evidence: `src/rfdetr/detr.py`)
- Inference facade → Prediction pipeline: runs prediction (evidence: `src/rfdetr/inference.py`)
- Prediction pipeline → Batch scheduling: schedules batches (evidence: `src/rfdetr/_prediction/pipelines.py`)
- Inference facade → LW-DETR model: loads native model (evidence: `src/rfdetr/inference.py`)
- LW-DETR model → DINOv2 backbone: uses backbone (evidence: `src/rfdetr/models/lwdetr.py`)
- LW-DETR model → Transformer: uses transformer (evidence: `src/rfdetr/models/lwdetr.py`)
- LW-DETR model → Prediction postprocess: configures postprocess (evidence: `src/rfdetr/models/lwdetr.py`)
- Inference facade → Model weights: loads weights (evidence: `src/rfdetr/inference.py`)
- User → Dataset formats: provides data (evidence: `README.md`)
- Dataset formats → COCO dataset: supports COCO (evidence: `src/rfdetr/datasets/coco.py`)
- User → Training orchestration: starts training
- Training orchestration → Training module: orchestrates training
- Training module → COCO dataset: loads dataset (evidence: `src/rfdetr/training/module_model.py`)
- Training module → LW-DETR model: trains model (evidence: `src/rfdetr/training/module_model.py`)
- Training module → COCO evaluation: registers evaluation (evidence: `src/rfdetr/training/module_model.py`)
- User → Model export: exports model
- Model export → Export metadata: writes metadata (evidence: `src/rfdetr/export/_runtime/metadata.py`)
- Inference facade → Runtime adapters: loads exported runtime (evidence: `src/rfdetr/inference.py`)
- Runtime adapters → Backend inference: dispatches backend (evidence: `src/rfdetr/export/_runtime/adapters.py`)
- Backend inference → Export metadata: reads metadata (evidence: `src/rfdetr/export/_runtime/adapters.py`)
