> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ovalbee.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ovalbee.com/_mcp/server.

# Train RF-DETR

> Train an RF-DETR (Nano, Small, Medium or Large) object detection model directly on OvalBee datasets, with the authors' own training code.

Runs on: gpu  Dockerfile

> **Note**
>
> First run can take longer while the worker pulls the configured Docker image.

## Overview

Fine-tunes an RF-DETR object detector from your workspace registry on OvalBee datasets, and registers the result as a new version of that model.

The node exports the train and validation datasets to COCO format inside its own working directory, trains on them, and uploads the checkpoints to the new version, so no conversion or upload node sits in between. The run publishes a live report that updates throughout training, and the **Best Loss** badge shows the lowest training loss reached.

This node runs RF-DETR Nano, Small, Medium and Large, the four detection sizes under Apache-2.0, with the authors' own `rfdetr` training code (the Lightning stack, their EMA and best-checkpoint rules), unchanged. Starting from a COCO catalog model fine-tunes the Objects365 and COCO pretrained weights; starting from one of your earlier runs starts from its trained weights.

```mermaid
flowchart LR
  n1["Dataset"] --> n2["Train/validation split"] --> n3["Train RF-DETR"] --> n4["Model version"]
```

#### Pretrained Models

* RF-DETR Large
* RF-DETR Medium
* RF-DETR Nano
* RF-DETR Small

## Prerequisites

| Requirement            | What you need                                                                                                                                                                                                                                              |
| ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **GPU worker**         | A worker with a GPU.                                                                                                                                                                                                                                       |
| **Annotated datasets** | A train and a validation dataset with object annotations, holding different images, e.g. the outputs of [Train/validation split](/node-library/nodes/sample-train-validation-split). The node refuses to start if the datasets hold no annotation classes. |
| **RF-DETR model**      | An RF-DETR detection model in the workspace registry: a catalog architecture copied in from the **Model** picker, or a version from an earlier training run.                                                                                               |

#### What the node builds

```text
📁 task working directory/
├── 📁 dataset/          ← the COCO export
│   ├── 📄 data.yaml
│   ├── 📁 images/{train,val}/
│   └── 📁 annotations/{train,val}.json
├── 📁 rfdetr_data/      ← the same images, linked, laid out the way RF-DETR reads them
└── 📁 artifacts/        ← the model (config.json + model.safetensors), logs, hyperparameters
```

Both directories are ephemeral: they live only for the duration of the task, and the checkpoints are uploaded to the model version before it ends. A rerun exports its datasets again.

## How it works

Exports the train and validation datasets to COCO format in one pass, so both splits share the same class index space.

Fetches the starting weights through the safe-weights check: the picked version's own weights, or for a catalog model the authors' COCO weights its catalog entry names.

Builds the training config from the architecture, the class count, and your **Hyperparameters**.

Trains with RF-DETR. The new version is created as training starts and receives checkpoints while the run goes, and the live report updates beside it.

Predicts on up to eight validation images for the report, then uploads the final checkpoints and metrics and marks the version ready.

## FAQ

#### How does it estimate data usefulness?

The node saves a checkpoint every tenth of the epoch budget (it sets `checkpoint_freq` for this), and after training it runs inference over the training split with a few of them -- near 10%, 25% and 50% of the run -- and with the final weights. For every labelled object it records the confidence of the best matching prediction of the right class, or zero when nothing matches, and scores each image by the average of one minus those confidences. An object counts as found once that confidence reaches 0.5, the default confidence threshold of the matching Predict node, and an image counts as learned once at least 80% of its objects are found.

Images learned in the first quarter of the run and never lost again are the ones the model needed least. Confident predictions that match no label are counted separately: they point at missing labels or genuine mistakes, and they do not decide whether an image was learned.

#### How is the Recommended keep set chosen?

Only images solved early and never forgotten can be dropped, easiest first, and every class keeps at least 80% of its instances. When nothing is safely droppable, the output stays empty rather than handing over a dataset the report advises against. To check the estimate, train again on the keep set from the same model this run started from and compare the two runs' evaluation metrics.

#### Do I need a conversion node in front of this one?

No. The node exports its datasets to COCO itself. Connect the datasets directly. RF-DETR trains on bounding boxes, so polygon and mask annotations are used through their bounding boxes.

#### What happens when I rerun the node?

Every run adds a new version to the model, or to **Destination model** when one is set, unless it continues a version that is not fully trained (below). Earlier versions stay in the registry and the source datasets aren't changed. When **Model** names the model itself rather than a pinned version, it follows the newest version that is ready or not fully trained, so a rerun that trains into the same model starts from the previous run's result, or continues that run when it did not finish.

#### Where do the trained files end up?

On the new model version: the best weights as `model.safetensors`, with the `config.json` that describes them (architecture, input size, classes in output order), the training log, and your hyperparameters. The periodic snapshots the usefulness estimate scores stay in the task. The version also records the class list, both datasets, the version training started from, the training report, and the metrics of the epoch whose weights it carries: mAP50, mAP50-95, and training loss.

#### What happens if training fails partway through?

The version is created before training starts and receives the best weights so far about every two minutes. At the end of the first epoch, and then at an epoch's end at most every two minutes, the node also saves a checkpoint into the version: the network, the optimizer, the position in the learning-rate schedule, the EMA weights and their update count, the mixed-precision scaler, the training loop's counters and callback state (early stopping's patience among them), the batch size and the best mAP so far, with the best weights and the training log as of that epoch. A checkpoint is about four times the size of the weights (the network, its EMA copy and the optimizer's two running averages): with Nano, 121 MB of network and 362 MB of training state, about 0.5 GB uploaded at every checkpoint while the next epoch trains; the version keeps only the latest one, and none once the run has finished. Training never waits for that upload, and no new checkpoint starts while one uploads, so a run that is killed loses the training since its last checkpoint that finished uploading: about one epoch or two minutes, whichever is longer, plus the time a checkpoint takes to upload. A run that stops after its first checkpoint leaves the version **Incomplete**: the model pickers offer it with its best weights so far, marked as not fully trained, and running the node with that version in **Model** (**Latest** picks it while it is the newest) continues the run from its last checkpoint into the same version, with the settings it started with. The continued run picks up the learning-rate schedule, the EMA and the batch size where the checkpoint left them (`batch_size: auto` is not measured again), but not the first epochs' random draws: a run with a `seed` is seeded anew from it and the epoch it continues at, so its remaining epochs see the images in new orders and with new augmentations. If the continued epochs never beat the best mAP the run had reached, the version keeps the best weights it had. The epoch that ends the run, its last one or an early stop, is not a checkpoint, so a run interrupted after it repeats that epoch. On Kubernetes, a run whose machine was taken away is retried and continues from its last checkpoint by itself. A run that stops before its first checkpoint marks its version failed, and it isn't offered in the model pickers. If uploading fails five times in a row, the node stops training rather than carry on with no way to save the result.

#### Why does a continued run refuse to start?

A run that continues an unfinished version trains with the settings it started with, so the node first compares the run with the checkpoint and refuses, naming each difference, when the hyperparameters (`epochs` included), the classes, the datasets, the architecture or the RF-DETR version differ. To train longer or with other settings, start from a fully trained version, such as the one the run started from, or save the unfinished one as a new version and train from that.

#### What if I leave the validation dataset empty?

The export points validation at the training images, so the mAP the run reports is measured on data the model trained on and reads higher than it will score on new images.

#### Which classes does the model learn?

When the train dataset is pinned to an ontology, the model learns that ontology's object classes in its order, and labels of any other class are skipped. Otherwise the classes come from the annotations in the datasets. The class list is also stored in the model's `config.json`, so prediction names classes the same way.

#### Which architecture should I start with?

Nano or Small when you need speed or an edge deployment, Large when accuracy matters more than latency. Roboflow's published COCO AP50:95 is 48.4 for Nano, 53.0 for Small, 54.7 for Medium and 56.5 for Large, each at its own native input size.

#### Why does the run stop with an out-of-memory error?

The architecture, `batch_size` and `resolution` together decide GPU memory. Lower `batch_size` first and raise `grad_accum_steps` to keep the effective batch (the default is 4 x 4 = 16), then `resolution`, before moving to a smaller model.

#### Why did the run fail right at the start?

Usually the datasets, the model, or the config. The datasets have to carry annotation classes, the picked version has to name one of the RF-DETR architectures listed above, and **Hyperparameters** has to be YAML whose keys RF-DETR's `TrainConfig` accepts. Every plain scalar field of that config - a number, a switch or one name out of a fixed set, `sync_bn` and `pack_targets` among them - may be set. A key the node sets itself (the dataset, output directory, weights, class list, `resume`, logger switches) is refused by name, and `resolution` has to be a multiple of 32. `multi_scale` and `compute_val_loss` are each a switch *or* one of their named values, which is all they take: `multi_scale: 1` is neither.

## Inputs

**`Train dataset`** `dataset` — required

Dataset the model learns from. Its annotations define the classes the trained model will detect. Key: `TRAIN_DATASET`.

---

**`Validation dataset`** `dataset` — required

Dataset held back to measure accuracy after each epoch. Leave it empty and accuracy is measured on the training assets instead, which makes the reported mAP look better than it is. Key: `VAL_DATASET`.

---

**`Estimate data usefulness`** `boolean` — required, default: true

After training, score every training image with checkpoints saved across the run to estimate how much of the data was actually needed, and publish the subset worth keeping. Sets checkpoint_freq to a tenth of the epoch budget so those checkpoints exist, and adds a few inference passes over the training split after the run. Key: `ESTIMATE_DATA_USEFULNESS`.

---

**`Model`** `model` — required

Model to fine-tune. A version copied from the zoo starts from the authors' COCO weights of that architecture, one from an earlier run from its trained weights. The run is registered as a new version of this model unless Destination Model names another one. When the version picked is not fully trained (Latest picks one when it is the newest), the run continues that training with the settings it started with, not the ones set here. Key: `MODEL`.

---

**`Destination model`** `model`

Model the new trained version is added to, when it should not go to the model you are training. Leave empty to add it to the Model above. Key: `DESTINATION_MODEL`.

---

**`Hyperparameters`** `yaml` — required

Training hyperparameters in YAML. Keys are RF-DETR's own `TrainConfig` fields (`epochs`, `batch_size`, `grad_accum_steps`, `lr`, `lr_encoder`, `weight_decay`, `warmup_epochs`, `ema_decay`, `use_ema`, `num_workers`, `eval_interval`, `early_stopping`, `seed`, `optimizer` and `lr_scheduler` presets, ...) plus `resolution` (a multiple of 32), `max_dets`, the detections per image validation counts (300 unless set), and `checkpoint_freq`. Your datasets, classes, output paths and starting weights are filled in for you, so keys such as `pretrain_weights`, `resume` or `output_dir` are refused, and so is any key the node does not list, or a value of the wrong type, at the start of the run. Key: `CONFIG`.

---

## Outputs

**`Report Asset`** `report`

ID of the asset containing the live RF-DETR training report. Shown as an artifact. Key: `REPORT_ID`.

---

**`Model`** `model`

Reference to the registry version this run produced, as `&lt;model id&gt;@&lt;version id&gt;`. It wires into the Model input of a predict, evaluate or export node and pins it to exactly these weights. Empty when the run could not be registered. Shown as an artifact. Key: `MODEL`.

---

**`Best Loss`** `string`

Lowest total training loss achieved (shown as a badge). Shown on the node as a badge. Key: `BEST_LOSS`.

---

**`Recommended keep set`** `dataset`

The training images this run's usefulness estimate says are worth keeping. To check the estimate, wire it into the Train dataset of another Train RF-DETR node that starts from the same model this run started from, and compare the two runs' evaluation metrics. Short-lived, so copy it if you want to keep it. Empty when the estimate found nothing safe to drop. Shown as an artifact. Key: `KEEP_DATASET`.

---

**`Keep share`** `string`

Share of the training images the keep set retains. Shown on the node as a badge. Selecting the badge opens `KEEP_DATASET`. Key: `KEEP_SHARE`.

---

## Models and configuration

**Model** is both what training starts from and where its result is filed: the run adds a version to that model. A version copied from the catalog starts from the authors' COCO weights its catalog entry names; one produced by an earlier run starts from its trained weights. Either way the new version records the picked version as its starting point.

Set **Destination model** to file the result elsewhere. The trained version is created there instead, and **Model** is then only the starting weights. Both pickers list only RF-DETR detection models of this workspace, with their ready versions and their incomplete ones, marked as not fully trained.

**Hyperparameters** is YAML in the key names of RF-DETR's own `TrainConfig`, plus `resolution` and `max_dets`. The dataset paths, the output directory and the class list are filled in by the node, so leave those out and set what you want to change: `epochs` for run length, `batch_size` and `grad_accum_steps` for memory and the effective batch, `resolution` for input size (a multiple of 32, default 640), `lr`, `lr_encoder` and `weight_decay`. `max_dets` is the number of detections per image that validation counts (300 unless set); it is applied to the validation metric the best checkpoint is chosen by. A key the node does not list, or a value of the wrong type, fails the run at its start; so do keys that would name a file or code, such as `pretrain_weights`, `resume`, or an `optimizer` or `lr_scheduler` import path.

The defaults are the authors' recipe at an effective batch of 16 on a 16 GB card: 100 epochs, learning rate 1e-4 (1.5e-4 for the encoder), EMA, multi-scale training and the step learning-rate drop. Removing a key restores RF-DETR's own default rather than disabling the feature. The best weights are the EMA weights with the highest validation mAP50-95 (the live weights when `use_ema` is off).

## Report

The report appears near the start of the run and updates as training produces results. It opens from the node.

#### Report sections

| Section                          | What it shows                                                                                                                                                                     |
| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Overview**                     | The model, parameter count, starting checkpoint, configured epochs, elapsed time, dataset sizes, and classes.                                                                     |
| **Predictions**                  | The best checkpoint applied to a fixed sample of up to eight validation images, added after training.                                                                             |
| **Evaluation metrics**           | mAP50-95, AP50, AP75, and AR@`max_dets` (average recall at `max_dets` detections per image, 300 unless you set `max_dets` in the hyperparameters) from the best validation epoch. |
| **Training plots**               | The training loss, COCO metric, and learning-rate series recorded during the run.                                                                                                 |
| **Artifacts**                    | The checkpoints written so far, replaced by a checkpoint download panel once the run finishes.                                                                                    |
| **Classes**                      | Each class with its model output index.                                                                                                                                           |
| **Hyperparameters**              | The **Hyperparameters** YAML as the node read it.                                                                                                                                 |
| **How to use the trained model** | A short local example that loads `model.safetensors` into the `rfdetr` package's network and predicts an image.                                                                   |

## Runtime

The node runs in its own GPU container. Memory use follows the architecture, the input size, and the batch size, so a model that won't fit is the first thing to check when a run dies early.

The first run takes longer while the worker pulls the image, and a catalog model downloads its pretrained weights on every run that starts from it. Every run exports its datasets before training starts, so a large dataset adds a download phase ahead of the first epoch.

## JSON config

Machine-readable node interface for automation and advanced usage.

#### Show JSON

```json
{
  "name": "Train RF-DETR",
  "description": "Train an RF-DETR (Nano, Small, Medium or Large) object detection model directly on OvalBee datasets, with the authors' own training code.",
  "category": "Train",
  "namespace": "ovalbee",
  "templateKey": "models/rfdetr/train_rf_detr",
  "version": "v1",
  "inputs": [
    {
      "key": "TRAIN_DATASET",
      "label": "Train dataset",
      "type": "dataset",
      "description": "Dataset the model learns from. Its annotations define the classes the trained model will detect.",
      "required": true,
      "default": null,
      "visibleWhen": null,
      "options": {
        "creatable": false
      }
    },
    {
      "key": "VAL_DATASET",
      "label": "Validation dataset",
      "type": "dataset",
      "description": "Dataset held back to measure accuracy after each epoch. Leave it empty and accuracy is measured on the training assets instead, which makes the reported mAP look better than it is.",
      "required": true,
      "default": null,
      "visibleWhen": null,
      "options": {
        "creatable": false
      }
    },
    {
      "key": "ESTIMATE_DATA_USEFULNESS",
      "label": "Estimate data usefulness",
      "type": "boolean",
      "description": "After training, score every training image with checkpoints saved across the run to estimate how much of the data was actually needed, and publish the subset worth keeping. Sets checkpoint_freq to a tenth of the epoch budget so those checkpoints exist, and adds a few inference passes over the training split after the run.\n",
      "required": true,
      "default": true,
      "visibleWhen": null
    },
    {
      "key": "MODEL",
      "label": "Model",
      "type": "model",
      "description": "Model to fine-tune. A version copied from the zoo starts from the authors' COCO weights of that architecture, one from an earlier run from its trained weights. The run is registered as a new version of this model unless Destination Model names another one. When the version picked is not fully trained (Latest picks one when it is the newest), the run continues that training with the settings it started with, not the ones set here.\n",
      "required": true,
      "default": null,
      "visibleWhen": null,
      "options": {
        "scope": "my",
        "framework": "rfdetr",
        "task_type": "object_detection",
        "include_incomplete_versions": true
      }
    },
    {
      "key": "DESTINATION_MODEL",
      "label": "Destination model",
      "type": "model",
      "description": "Model the new trained version is added to, when it should not go to the model you are training. Leave empty to add it to the Model above.\n",
      "required": false,
      "default": null,
      "visibleWhen": null,
      "options": {
        "scope": "my",
        "framework": "rfdetr",
        "task_type": "object_detection"
      }
    },
    {
      "key": "CONFIG",
      "label": "Hyperparameters",
      "type": "yaml",
      "description": "Training hyperparameters in YAML. Keys are RF-DETR's own `TrainConfig` fields (`epochs`, `batch_size`, `grad_accum_steps`, `lr`, `lr_encoder`, `weight_decay`, `warmup_epochs`, `ema_decay`, `use_ema`, `num_workers`, `eval_interval`, `early_stopping`, `seed`, `optimizer` and `lr_scheduler` presets, ...) plus `resolution` (a multiple of 32), `max_dets`, the detections per image validation counts (300 unless set), and `checkpoint_freq`. Your datasets, classes, output paths and starting weights are filled in for you, so keys such as `pretrain_weights`, `resume` or `output_dir` are refused, and so is any key the node does not list, or a value of the wrong type, at the start of the run.\n",
      "required": true,
      "default": "epochs: 100\nbatch_size: 4\ngrad_accum_steps: 4\nresolution: 640\nlr: 0.0001\nlr_encoder: 0.00015\nweight_decay: 0.0001\n",
      "visibleWhen": null
    }
  ],
  "outputs": [
    {
      "key": "REPORT_ID",
      "label": "Report Asset",
      "type": "report",
      "description": "ID of the asset containing the live RF-DETR training report.",
      "artifact": true,
      "badge": false,
      "badgeOpens": null,
      "hidden": false
    },
    {
      "key": "MODEL",
      "label": "Model",
      "type": "model",
      "description": "Reference to the registry version this run produced, as `<model id>@<version id>`. It wires into the Model input of a predict, evaluate or export node and pins it to exactly these weights. Empty when the run could not be registered.\n",
      "artifact": true,
      "badge": false,
      "badgeOpens": null,
      "hidden": false
    },
    {
      "key": "BEST_LOSS",
      "label": "Best Loss",
      "type": "string",
      "description": "Lowest total training loss achieved (shown as a badge).",
      "artifact": false,
      "badge": true,
      "badgeOpens": null,
      "hidden": false
    },
    {
      "key": "KEEP_DATASET",
      "label": "Recommended keep set",
      "type": "dataset",
      "description": "The training images this run's usefulness estimate says are worth keeping. To check the estimate, wire it into the Train dataset of another Train RF-DETR node that starts from the same model this run started from, and compare the two runs' evaluation metrics. Short-lived, so copy it if you want to keep it. Empty when the estimate found nothing safe to drop.\n",
      "artifact": true,
      "badge": false,
      "badgeOpens": null,
      "hidden": false
    },
    {
      "key": "KEEP_SHARE",
      "label": "Keep share",
      "type": "string",
      "description": "Share of the training images the keep set retains.",
      "artifact": false,
      "badge": true,
      "badgeOpens": "KEEP_DATASET",
      "hidden": false
    }
  ],
  "runtime": {
    "type": "docker",
    "devices": [
      "gpu"
    ],
    "dockerImage": "ovalbee/node-rfdetr:0.0.8"
  },
  "widgets": {
    "widget": {
      "id": "report-preview",
      "settings": {
        "reportAsset": {
          "type": "variable",
          "value": "self.outputs.REPORT_ID"
        },
        "name": {
          "type": "input",
          "value": "Open training report"
        }
      }
    }
  }
}
```

## References

#### Sources and related pages

* [Predict RF-DETR](/node-library/nodes/models-rfdetr-predict-rf-detr) runs the trained model over a dataset.
* [Export RF-DETR](/node-library/nodes/models-rfdetr-export-rf-detr) converts the trained checkpoint to deployment formats.
* [RF-DETR](https://github.com/ShihuaHuang95/RF-DETR) is the upstream training framework.