Why is RF-DETR segmentation training slow, and what makes it faster?

On COCO, 60% of an RF-DETR segmentation epoch is spent in validation, not training: rfdetr upsamples every predicted mask to its image’s full size and encodes it on the CPU before scoring it. rfdetr’s own eval_masks_head_resolution=True scores the masks on the mask head’s grid instead, which made a warm epoch 2.35x faster on an NVIDIA H100 (321.5 s to 136.7 s). That score reads about 15% low, but it ranks epochs the same way, so it still picks the best checkpoint; score that checkpoint once at full resolution and report that number. Separately, upgrading rfdetr from 1.8.3 to 1.11.2 made detection training 3.3x faster on the same data, with a higher mAP. We measured all of this on 2026-10-16 and 17. The rest of this post is where an epoch’s time goes, and which other options did and did not help.

The setup

The data is COCO-5k, a public 5,000-image subset of COCO 2017. The models are RF-DETR medium: detection at 576 px with batch size 12, segmentation at 432 px with batch size 8, with horizontal flips and EMA. Every run used one H100 with 16 vCPUs. A callback timed every batch: waiting for data is the gap between one batch ending and the next starting, compute is the training step itself, and validation is the epoch’s evaluation pass. Epoch times are the second, warm epoch.

rfdetr 1.11.2 trains detection 3.3x faster than 1.8.3

The same export and config, 10 epochs each:

Task rfdetr Training time mAP mAP50 Peak GPU memory Mean GPU use
Detection, 576 px 1.8.3 2,755 s 0.465 0.636 9.0 GiB 24%
Detection, 576 px 1.11.2 830 s 0.490 0.656 12.9 GiB 49%
Segmentation, 432 px 1.8.3 4,497 s 0.361 0.556 13.7 GiB 20%
Segmentation, 432 px 1.11.2 3,265 s 0.357 0.564 10.9 GiB 21%

Segmentation’s mAP is mask mAP. The 1.11.2 runs report their best checkpoint (epoch 7 in both) and the 1.8.3 detection run its last epoch, but 1.11.2’s detection mAP is flat at about 0.49 from epoch 5 on, so the gain is not a checkpoint choice. Segmentation’s accuracy is within run-to-run noise.

Even on 1.11.2 the GPU is busy only half the time for detection and a fifth of the time for segmentation. The next measurement shows why.

Where an epoch goes

rfdetr 1.11.2, one warm epoch:

Task Epoch Training compute Waiting for data Validation
Detection, batch 12 57.8 s 48.2 s 0.6 s 7.0 s
Segmentation, batch 8 260.1 s 99.1 s 0.8 s 158.6 s
  • The data loader is not the bottleneck. Waiting for data is 0.3-1.1% of every epoch we measured, so more loader workers or GPU-side augmentation cannot buy anything. 15 workers instead of 12 was within the roughly 10% spread between two identical machines.
  • Detection’s GPU idles inside the training step. The step is overhead-bound, and batch size is the lever: batch 4 trains 32 images a second, batch 12 trains 72.
  • Segmentation spends 60% of its epoch in validation, scoring full-resolution masks.

Options that did not help

  • compile=True failed with a BackendCompilerFailed error from torch’s inductor after 27 minutes of compiling.
  • cuda_graphs=True crashed at the first graph capture at batch size 12. At batch size 4 it ran, 7% faster per epoch (122.0 s to 113.3 s), for 7.7x the GPU memory (4.7 GiB to 36.1 GiB).
  • eval_batch_size=48 changed nothing: detection’s validation is 7 s of a 58 s epoch.
  • Turning gradient checkpointing off made segmentation’s training step 3% faster at 432 px (99.1 s to 95.9 s). We keep it on, because it prevents running out of memory at 768 px.

Both the compile and CUDA graph failures were on torch 2.5.1, the version our export path is validated against. A newer torch may behave differently.

Score each epoch on the mask head’s grid

By default, rfdetr’s segmentation validation upsamples every predicted mask to its image’s full resolution and run-length encodes it on the CPU, then scores COCO mask mAP. With eval_masks_head_resolution=True, masks are compared at the mask head’s own resolution instead, a quarter of the input side (108 x 108 at 432 px), with the ground truth downsized to it. Measured side by side on the same day:

Validation masks Warm epoch Validation Training compute
Full resolution (rfdetr’s default) 321.5 s 203.1 s 116.1 s
Mask head’s grid 136.7 s 23.7 s 111.1 s

Validation is 8.6x faster. (Validation ran slower on this day’s machines than in the table above, 203 s against 159 s, which is why we measured both variants together.)

rfdetr’s documentation warns that the score is then not comparable to a full-resolution run. To see by how much, we scored the same weights both ways:

Weights Full-resolution mask mAP / mAP50 Mask-head grid mAP / mAP50 Box mAP
Trained 10 epochs 0.357 / 0.564 0.304 / 0.527 0.448
Trained 2 epochs 0.273 / 0.431 0.234 / 0.401 0.343

The grid score reads 0.04-0.05 low on COCO, where small objects collapse on a 108-pixel grid. But it reads low by the same proportion for both models (full resolution is 1.17 times the grid score), so it orders epochs the same way, and that is all best-checkpoint selection and early stopping need from it. Box mAP does not involve masks and is unchanged. Inference is unaffected too: predict() always returns masks at the image’s size.

So validate every epoch on the grid, then score the checkpoint you keep once at full resolution and report that number. The final pass costs about one old validation (175-185 s here), so a run of N epochs goes from N x 321.5 s to N x 136.7 s + about 180 s: 1.4x faster for 2 epochs, 2.1x for 10, 2.3x for 50.

from rfdetr import RFDETRSegMedium

model = RFDETRSegMedium()
# Score each epoch on the mask head's grid
model.train(
    dataset_dir="dataset",
    output_dir="output",
    epochs=50,
    batch_size=8,
    eval_masks_head_resolution=True,
)

# Score the checkpoint training kept, once, at full resolution
best = RFDETRSegMedium.from_checkpoint("output/checkpoint_best_total.pth")
metrics = best.evaluate(
    split="val",
    dataset_dir="dataset",
    eval_masks_head_resolution=False,
)
print(metrics)

On Pictograph

Pictograph trains RF-DETR segmentation this way by default: every epoch is scored on the mask head’s grid, and the mAP a model reports is its shipped checkpoint scored at full resolution, so it stays comparable with models trained before the change. The live training chart labels the per-epoch number as the grid score.

from pictograph import Client, TrainingRun

client = Client()
run: TrainingRun = client.training.create(
    dataset="parts-inspection",
    export="parts-inspection-v1",
    pipeline_type="rfdetr_segmentation",
    name="parts-segmenter",
    gpu_type="a100",
    config={"epochs": 50, "model_size": "medium"},
)
print(run.status, run.model_id)

The training guide covers pipelines, GPUs and hyperparameters, and YOLOX vs RF-DETR helps choose between them. Once a model is trained, T4 vs L4 latency, measured shows how fast it serves live video.

Build your first vision tool

$25 of free compute to start. No card required.