> 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 RT-DETR

> Train an RT-DETR, RT-DETRv2 or RT-DETRv4 object detection model directly on OvalBee datasets, from the original code bases.

Runs on: gpu  Dockerfile

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

## Overview

Fine-tunes an RT-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 three generations of the detector from their original code bases: RT-DETR and RT-DETRv2 (ResNet-vd backbones, S to X) and RT-DETRv4 (HGNetV2 backbones, S to X). Every catalog entry is Apache-2.0. RT-DETRv4 was trained upstream with a DINOv3 teacher; this node fine-tunes it without the teacher, so no DINOv3 files are needed.

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

#### Pretrained Models

* RT-DETR R18vd
* RT-DETR R34vd
* RT-DETR R50vd_m
* RT-DETR R50vd
* RT-DETR R101vd
* RT-DETRv2-S (r18vd, original)
* RT-DETRv2-M\* (r34vd, original)
* RT-DETRv2-M (r50vd_m, original)
* RT-DETRv2-L (r50vd, original)
* RT-DETRv2-X (r101vd, original)
* RT-DETRv4-S
* RT-DETRv4-M
* RT-DETRv4-L
* RT-DETRv4-X

## 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. |
| **RT-DETR model**      | An RT-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
└── 📁 artifacts/        ← checkpoints, logs, the training config
```

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.

Loads the starting weights: the picked version's own checkpoint, or the public COCO weights of its architecture for a catalog model.

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

Trains with RT-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. RT-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 and last checkpoints (not the periodic ones RT-DETR writes as it goes), the training config the weights need at prediction time, the training log, and your hyperparameters. The version also records the class list, both datasets, the version training started from, the training report, and the mAP50, mAP50-95 and training loss of the epoch whose weights it carries.

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

The version receives the latest best and last checkpoints 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 and its warmup, the EMA weights and their update count, the mixed-precision scaler and the best mAP so far, with the best weights and logs as of that epoch. Training never waits for a checkpoint's 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 seeds its random generators anew from the run's seed and the epoch it continues at, so it does not repeat the first epochs' sample order and augmentations, and an epoch that does not beat the best mAP reached before the interruption leaves the version's best weights as they were. The run's last epoch 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 (`epoches` included), the classes, the datasets, the architecture or the revision of the RT-DETR or RT-DETRv4 code the image trains with differ. To train longer or with other settings, start from a fully trained version, 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 inside the checkpoints, so prediction names classes the same way.

#### Which architecture should I start with?

The small variants (RT-DETRv2-S, RT-DETRv4-S) when you need speed or an edge deployment, and the X variants when accuracy matters more than latency. RT-DETRv4 has the highest published COCO accuracy per size.

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

The architecture, `batch_size`, and `eval_spatial_size` together decide GPU memory. Lower the batch size first, then the input size, before moving to a smaller backbone.

#### 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 RT-DETR architectures listed above, and **Hyperparameters** has to be YAML whose keys the trainer accepts.

## 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 the entry names, one from an earlier run starts from its weights, built with the architecture settings it was trained with. 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 settings in YAML, in the key names of the upstream trainer: how many epochs to run, batch size, input size. Anything else of the upstream config can be overridden here too. The augmentation and multi-scale schedule is fitted to the number of epochs unless you set it. `max_dets` is the number of detections per image that validation counts (default 300). Dataset paths and the number of classes are filled in for you. Keys that would load weights, code or other files - `resume`, `tuning`, `pretrained: true`, `__include__`, paths - are refused, and the classes the architecture builds cannot be swapped: training starts from the weights of Model. Key: `CONFIG`.

---

## Outputs

**`Report Asset`** `report`

ID of the asset containing the live RT-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 RT-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 has no weights of its own, so the run downloads the public COCO weights of that architecture. One produced by an earlier run continues from its checkpoint. 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 RT-DETR detection models of this workspace, with their ready versions and their incomplete ones, marked as not fully trained.

**Hyperparameters** is the RT-DETR training config as YAML. The dataset paths and the class count are injected by the node from its own export, so leave those out and set what you want to change: `epoches` for run length, `batch_size` for memory, `eval_spatial_size` for input resolution. Nested keys merge into the architecture's base config rather than replacing whole sections.

Set `seed: 0` or another integer up to 2147483647 in **Hyperparameters** to choose the training
seed; when omitted, the seed is 0. The effective config (`hyperparameters/all.yml`) and training checkpoints record
it. A run that continues an unfinished version seeds the trainer from that seed and the epoch it
continues at, so it draws new sample orders and augmentations rather than the first epochs' again.
The node enables mixed precision by default. Set `use_amp: false` to train in full precision,
or `use_amp: true` to enable it explicitly; a continued run keeps the setting it started with.

The starting weights have to fit the network your settings build, every layer of it except the class heads, which follow the class count of your datasets. A setting that changes the shape of another layer stops the run as it starts, naming the layers that no longer fit.

The defaults are a full training schedule, including the augmentation policy, the EMA settings, and the learning-rate curve. Removing a key restores the architecture's own default rather than disabling the feature.

## 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, 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 loss, COCO metric, and learning-rate series recorded during the run.                                                                                                          |
| **TensorBoard**                  | The raw TensorBoard event stream. Empty until RT-DETR writes events.                                                                                                              |
| **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 the checkpoint 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 RT-DETR",
  "description": "Train an RT-DETR, RT-DETRv2 or RT-DETRv4 object detection model directly on OvalBee datasets, from the original code bases.",
  "category": "Train",
  "namespace": "ovalbee",
  "templateKey": "models/rtdetr/train_rt_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 the entry names; one from an earlier run starts from its weights, built with the architecture settings it was trained with. 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": "rtdetr",
        "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": "rtdetr",
        "task_type": "object_detection"
      }
    },
    {
      "key": "CONFIG",
      "label": "Hyperparameters",
      "type": "yaml",
      "description": "Training settings in YAML, in the key names of the upstream trainer: how many epochs to run, batch size, input size. Anything else of the upstream config can be overridden here too. The augmentation and multi-scale schedule is fitted to the number of epochs unless you set it. `max_dets` is the number of detections per image that validation counts (default 300). Dataset paths and the number of classes are filled in for you. Keys that would load weights, code or other files - `resume`, `tuning`, `pretrained: true`, `__include__`, paths - are refused, and the classes the architecture builds cannot be swapped: training starts from the weights of Model.\n",
      "required": true,
      "default": "epoches: 30\nbatch_size: 8\neval_spatial_size: [640, 640]\ncheckpoint_freq: 5\nmax_dets: 300\nuse_amp: true\n",
      "visibleWhen": null
    }
  ],
  "outputs": [
    {
      "key": "REPORT_ID",
      "label": "Report Asset",
      "type": "report",
      "description": "ID of the asset containing the live RT-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 RT-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-rtdetr:0.0.15"
  },
  "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 RT-DETR](/node-library/nodes/models-rtdetr-predict-rt-detr) runs the trained model over a dataset.
* [Export RT-DETR](/node-library/nodes/models-rtdetr-export-rt-detr) converts the trained checkpoint to deployment formats.
* [RT-DETR](https://github.com/ShihuaHuang95/RT-DETR) is the upstream training framework.