> 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.

# Export RF-DETR

> Convert a trained RF-DETR model to PyTorch, ONNX and TensorRT and attach every format to the model it came from.

Runs on: gpu  Dockerfile

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

## Overview

Converts a trained RF-DETR checkpoint into each format you select and attaches each one to the model version the weights came from.

The exports stay on that version, and the model page lists them for download. A format already exported from the same checkpoint at the same precision is reused instead of converted again.

```mermaid
flowchart LR
  n1["Train RF-DETR"] --> n2["Export RF-DETR"] --> n3["Exported model files"]
```

## Prerequisites

| Requirement            | What you need                                                                                                                                                                                                              |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **RF-DETR checkpoint** | An RF-DETR model version with weights of its own, e.g. one from [Train RF-DETR](/node-library/nodes/models-rfdetr-train-rf-detr). A model copied from the catalog stores no weights in this instance to attach exports to. |
| **NVIDIA GPU**         | A GPU worker with a working NVIDIA runtime. The node requests one for every run, and TensorRT compiles the engine on it.                                                                                                   |

## How it works

Checks each ticked format against the exports already on the model version and skips the ones built from the same checkpoint at the same precision.

Fetches the weights through the safe-weights check: a version trained here as `model.safetensors` with the `config.json` that records its architecture, input size and classes.

Rebuilds the model together with its postprocessor, so the exported graph returns labels, boxes, and scores directly instead of raw tensors, then traces it to ONNX at the input size recorded in `config.json`.

Builds the TensorRT engine from that same ONNX graph when its checkbox is ticked, so asking for both costs one trace.

Attaches every produced file, and the class list, to the source model version.

## FAQ

#### Does the export replace the trained model?

No. Each export is another file on the version it came from, so one checkpoint can carry its PyTorch, ONNX, and TensorRT exports side by side while the weights stay untouched.

#### Why tick several formats in one run instead of one node each?

The TensorRT engine is built from an intermediate ONNX graph. Ticking both in one run traces the model once and reuses that graph, where two separate runs would trace it twice.

#### What input size does the exported model expect?

The input size recorded in the model's `config.json`, which is 640 by 640 unless training changed it. Both the ONNX graph and the TensorRT engine are built for one image per call (batch 1): RF-DETR's export forward is traced with a fixed batch. The inputs are `images` (RGB in \[0, 1], the graph normalises) and `orig_target_sizes` (width, height); the outputs are `labels`, `boxes` (xyxy in original pixels) and `scores`, 300 detections.

#### Should I change the ONNX opset?

Only when your runtime rejects the default. A lower opset can widen compatibility with older runtimes, at the cost of failing when the model uses a newer operator.

#### What does the export folder contain besides the model file?

A `classes.txt` listing one class per line, so line N names the class the graph reports as index N. It is copied from the version, which is the index space the model was trained on, and the checkpoint answers only when the version records none.

## Inputs

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

Model whose weights are exported, e.g. a version trained in this workspace. A model copied from the catalog stores no weights in this instance to attach exports to, so train from it first. Key: `MODEL`.

---

**`Export to PyTorch`** `boolean` — required, default: false

Attach the weights file itself as a PyTorch export (`model.safetensors` for a version trained in this workspace). Key: `EXPORT_PYTORCH`.

---

**`Export to ONNX`** `boolean` — required, default: false

Trace the model to an ONNX graph with a fixed batch of 1 (inputs `images` and `orig_target_sizes`, outputs `labels`, `boxes`, `scores`). Key: `EXPORT_ONNX`.

---

**`Export to TensorRT`** `boolean` — required, default: false

Build a TensorRT engine. It is cut from an intermediate ONNX graph, so ticking ONNX as well costs one trace rather than two. The engine takes a batch of 1. Key: `EXPORT_TENSORRT`.

---

**`ONNX opset`** `integer` — required, default: 17

Version of the ONNX operator set the exported graph targets. Lower it when the runtime you deploy to cannot read the default. Minimum: `11`. Key: `OPSET`.

---

**`TensorRT FP16`** `boolean` — required, default: false

Builds the engine with half-precision weights, which run faster and use less GPU memory at a small cost in accuracy. Key: `TRT_FP16`.

---

## Outputs

**`Exported formats`** `string`

Format keys this run produced, comma separated. Read by the download widget. Hidden from the flow editor. Key: `EXPORT_FORMATS`.

---

**`Model`** `model`

The model that was exported, as `&lt;model id&gt;@&lt;version id&gt;` - the same reference this node was given. An export is another file on that version, not a version of its own, so this output wires on to anything the input accepts. Shown as an artifact. Key: `MODEL`.

---

## Widgets

The model download widget downloads what this run produced: a single file when the run produced exactly one, and a zip of every ticked format, class lists included, when it produced more. The model version page lists the same files one by one.

## Runtime

The export runs in the RF-DETR Docker image on a GPU worker. Every run checks that the GPU it was given works before it downloads anything, and stops if it does not, so a broken worker fails in seconds instead of converting on the CPU at the GPU price.

The image carries TensorRT, NVIDIA software under [NVIDIA's license](https://docs.nvidia.com/deeplearning/tensorrt/latest/reference/sla.html).

## JSON config

Machine-readable node interface for automation and advanced usage.

#### Show JSON

```json
{
  "name": "Export RF-DETR",
  "description": "Convert a trained RF-DETR model to PyTorch, ONNX and TensorRT and attach every format to the model it came from.",
  "category": "Models",
  "namespace": "ovalbee",
  "templateKey": "models/rfdetr/export_rf_detr",
  "version": "v1",
  "inputs": [
    {
      "key": "MODEL",
      "label": "Model",
      "type": "model",
      "description": "Model whose weights are exported, e.g. a version trained in this workspace. A model copied from the catalog stores no weights in this instance to attach exports to, so train from it first.\n",
      "required": true,
      "default": null,
      "visibleWhen": null,
      "options": {
        "framework": "rfdetr",
        "task_type": "object_detection"
      }
    },
    {
      "key": "EXPORT_PYTORCH",
      "label": "Export to PyTorch",
      "type": "boolean",
      "description": "Attach the weights file itself as a PyTorch export (`model.safetensors` for a version trained in this workspace).",
      "required": true,
      "default": false,
      "visibleWhen": null
    },
    {
      "key": "EXPORT_ONNX",
      "label": "Export to ONNX",
      "type": "boolean",
      "description": "Trace the model to an ONNX graph with a fixed batch of 1 (inputs `images` and `orig_target_sizes`; outputs `labels`, `boxes`, `scores`).",
      "required": true,
      "default": false,
      "visibleWhen": null
    },
    {
      "key": "EXPORT_TENSORRT",
      "label": "Export to TensorRT",
      "type": "boolean",
      "description": "Build a TensorRT engine. It is cut from an intermediate ONNX graph, so ticking ONNX as well costs one trace rather than two. The engine takes a batch of 1.",
      "required": true,
      "default": false,
      "visibleWhen": null
    },
    {
      "key": "OPSET",
      "label": "ONNX opset",
      "type": "number",
      "description": "Version of the ONNX operator set the exported graph targets. Lower it when the runtime you deploy to cannot read the default.",
      "required": true,
      "default": 17,
      "visibleWhen": null,
      "options": {
        "type": "integer",
        "min": 11
      }
    },
    {
      "key": "TRT_FP16",
      "label": "TensorRT FP16",
      "type": "boolean",
      "description": "Builds the engine with half-precision weights, which run faster and use less GPU memory at a small cost in accuracy.",
      "required": true,
      "default": false,
      "visibleWhen": null
    }
  ],
  "outputs": [
    {
      "key": "EXPORT_FORMATS",
      "label": "Exported formats",
      "type": "string",
      "description": "Format keys this run produced, comma separated. Read by the download widget.",
      "artifact": false,
      "badge": false,
      "badgeOpens": null,
      "hidden": true
    },
    {
      "key": "MODEL",
      "label": "Model",
      "type": "model",
      "description": "The model that was exported, as `<model id>@<version id>` - the same reference this node was given. An export is another file on that version, not a version of its own, so this output wires on to anything the input accepts.\n",
      "artifact": true,
      "badge": false,
      "badgeOpens": null,
      "hidden": false
    }
  ],
  "runtime": {
    "type": "docker",
    "devices": [
      "gpu"
    ],
    "dockerImage": "ovalbee/node-rfdetr:0.0.8"
  },
  "widgets": {
    "widget": {
      "id": "model-download",
      "settings": {
        "assetId": {
          "type": "variable",
          "value": "self.outputs.MODEL"
        },
        "format": {
          "type": "variable",
          "value": "self.outputs.EXPORT_FORMATS"
        }
      }
    }
  }
}
```