RF-DETR for Industrial Anomaly
Detection and Segmentation

Abstract. We evaluate RF-DETR1, a real-time detection transformer, as an anomaly detector and segmenter on the VisA industrial inspection dataset, fine-tuning one model per product class. While it is comparable to the supervised baseline when annotated samples are sufficient, we find that in the few-shot regime, with only 5–10 labelled anomalous images, it outperforms the supervised baselines by a significant margin, verifying its ability to transfer to specialized industrial products. Furthermore, we break down performance by defect size and demonstrate that the pixel-level scores are mainly attributed to large defects, which are easier to detect. Spotting and localizing small-area defects remains an open challenge.

1Anomaly Detection & Segmentation

Anomaly detection is the task of identifying image samples that deviate from the norm, deciding whether an image contains any defect at all. Anomaly segmentation goes one step further and localizes the defective regions within each sample. In real-world problems such as the quality control of industrial products, abnormal samples are generally difficult to collect. Therefore, existing solutions focus on training models that identify data that deviate from the learned distribution of normality as anomalies. However, some deviations — such as lighting or orientation — are caused by the imaging pipeline rather than the product itself, and labelled defects are the only signal that tells the two apart. In this report, we focus on supervised anomaly detection and segmentation.

This problem poses the following two main challenges:

RF-DETR1 — a lightweight object-detection and instance-segmentation model built for fine-tuning on small domain-specific datasets — fits both constraints. In this report, we evaluate the strengths of RF-DETR and the remaining challenges.

2Dataset and Evaluation Metrics

VisA (Visual Anomaly) is one of the standard industrial anomaly-detection benchmarks: 10,821 high-resolution images across 12 product subsets — 9,621 normal and 1,200 anomalous, as depicted in Figure 1. The subsets span four printed circuit boards, capsules, and candles photographed in multi-object layouts, and six food products — cashews, chewing gum, two kinds of fryum, and two kinds of macaroni. The defects are physical damage on real products: scratches, dents, contamination spots, missing parts, bent leads. A detailed illustration of the defects can be found in Figure 2.

In this report we adopt (1) the supervised 2-class “high-shot” split (§4.2), which moves 60 anomalous images per subset into the training set, and (2) the supervised 2-class “few-shot” split (§4.3), which includes only 5 or 10 anomalous images per subset in the training set.

candlecat_candle
capsulescat_capsules
cashewcat_cashew
chewinggumcat_chewinggum
fryumcat_fryum
macaroni1cat_macaroni1
macaroni2cat_macaroni2
pcb1cat_pcb1
pcb2cat_pcb2
pcb3cat_pcb3
pcb4cat_pcb4
pipe_fryumcat_pipe_fryum
Fig. 1 — Sample images for each product in Visual Anomaly (VisA) dataset. Ground-truth defect masks are annotated in  red.
Fig. 2 — illustration of ground-truth defect masks (3× crops)
capsules · crop 3×pipe_1_image
capsules · mask > 0pipe_3_mask_bin
capsules · mask on croppipe_4_overlay
candle · crop 3×zoom_candle_crop
candle · mask > 0zoom_candle_mask_bin
candle · mask on cropzoom_candle_mask_overlay
fryum · crop 3×zoom_fryum_crop
fryum · mask > 0zoom_fryum_mask_bin
fryum · mask on cropzoom_fryum_mask_overlay
Fig. 2 — Illustration of ground-truth defect masks. Every panel is a 3× crop. Left: the image crop; middle: the shipped mask; right: the mask painted back onto the crop in red. The smallest annotated defect in these three maps is 2×5 px for capsules and 2×3 px for candle and fryum, at native resolution.

3Method

3.1  RF-DETR-Seg Model

RF-DETR is a family of real-time detection transformers built on a DINOv2-pretrained backbone4; RF-DETR-Seg is its instance-segmentation variant, which adds a mask head on top of the detector. It predicts each defect as a mask, along with the corresponding bounding box and confidence score. The neural architecture search (NAS) pretraining makes RF-DETR generalize better to diverse target datasets, as verified by the RF100-VL5 experiment in the original paper. This ability makes RF-DETR a suitable choice for the anomaly detection and segmentation task, as annotated defective samples are usually scarce and specific to each industrial product.

For image-level anomaly detection, we use the maximum confidence score across all predicted defects as the anomaly score. If no defects are predicted, the anomaly score is set to 0. For pixel-level anomaly segmentation, we use the masks produced by the segmentation head.

3.2  Training objective

Training follows the standard DETR recipe. Each ground-truth defect is first matched one-to-one with the predicted instance that fits it best (Hungarian matching); the loss is then computed over the matched pairs, as a weighted sum of three parts:

4Experiments

Due to limited computational resources, we use the COCO-pretrained6 RF-DETR-Seg-Small model with 384×384 input resolution and 100 queries. We fine-tune the model separately for each of the 12 VisA product classes and evaluate on its official test split. In the high-shot setting, the model trains on the entire training split. In the few-shot setting, it instead sees only N anomalous and N normal training images (N = 5 or 10), drawn with 5 different sampling seeds, and every few-shot number reported below is averaged over those 5 seeds. Every run trains for 30 epochs with identical hyperparameters (AdamW, lr 5×10−5, effective batch size 16), and all reported numbers come from the final-epoch EMA weights.

4.1  Evaluation metrics

4.2  Supervised high-shot

In this report, we compare to the baselines reported in the original VisA paper: three self-supervised pre-training methods (SimSiam, MoCo, SimCLR) and a supervised pre-training baseline. They propose the SPot-the-Difference (SPD) regularization loss to increase model invariance to slight global changes by contrastive learning. Their supervised baseline fine-tunes an ImageNet-pretrained ResNet-50: a standard binary classifier for image-level detection, and a U-Net with a ResNet-50 encoder for segmentation. In the VisA paper, their recommended resolution is 800×800. Although the RF-DETR-Seg-Small model in this report runs at only 384×384, it achieves results comparable to the supervised baseline, as shown in Tables 1 and 2.

Table 1 — Supervised high-shot anomaly detection (image-level), using the full official training split. The table reports the mean across 12 products.

MethodAU-PR AU-ROC
SimSiam+SPD93.298.7
MoCo+SPD94.298.8
SimCLR+SPD92.798.6
Supervised ResNet+SPD98.399.7
RF-DETR96.298.7

Table 2 — Supervised high-shot anomaly segmentation (pixel-level), using the full official training split. The table reports the mean across 12 products.

MethodAU-PR AU-ROC
SimSiam+SPD59.798.1
MoCo+SPD64.497.9
SimCLR+SPD68.295.7
Supervised Unet+SPD71.998.5
RF-DETR70.590.7

4.3  Supervised few-shot

We report the results of image-level anomaly detection in Table 3 and pixel-level anomaly segmentation in Table 4. We found that RF-DETR outperforms the supervised baselines on both metrics. In the 5-shot setting, where training samples are scarcest, the margin is significant: RF-DETR reaches 70.6 image-level AU-PR against 59.8 for Supervised ResNet+SPD, and 89.5 versus 85.9 AU-ROC. Similar results are observed in anomaly segmentation — 29.7 versus 18.7 AU-PR and 84.8 versus 75.9 AU-ROC over Supervised Unet+SPD. The results suggest that RF-DETR can adapt to a specialized industrial product with only a few samples.

We hypothesize that this can be attributed to the architecture augmentation via weight-sharing NAS in the training process of RF-DETR. Because the model has learned across various image resolutions, patch sizes, and query counts, it can be fine-tuned to a target dataset with only a few samples. This is consistent with the RF100-VL5 experiments in the RF-DETR paper, which showed that the model transfers well across diverse target domains. The detailed results for each product class are shown in the collapsible Tables 5 and 6 (click to expand).

Table 3 — Anomaly classification (image-level). The table reports the mean across 12 products, averaged over 5 sampling seeds (± std across seeds).

Method5-shot 10-shot
AU-PRAU-ROC AU-PRAU-ROC
SimSiam+SPD56.184.067.690.8
MoCo+SPD56.483.968.090.1
SimCLR+SPD47.479.959.086.1
Supervised ResNet+SPD59.885.971.292.1
RF-DETR70.6 ±1.389.5 ±0.977.9 ±0.893.0 ±0.7

Table 4 — Anomaly segmentation (pixel-level). The table reports the mean across 12 products, averaged over 5 sampling seeds (± std across seeds).

Method5-shot 10-shot
AU-PRAU-ROC AU-PRAU-ROC
SimSiam+SPD18.276.029.783.2
MoCo+SPD22.178.532.884.9
SimCLR+SPD18.974.525.178.2
Supervised Unet+SPD18.775.930.681.8
RF-DETR29.7 ±4.084.8 ±1.947.8 ±6.189.6 ±2.9
Table 5 — Per-subset anomaly detection results

Table 5 — Per-subset anomaly detection (image-level) results; each cell is the mean over the 5 sampling seeds (final-epoch EMA weights, 384×384 eval grid, official AUPR convention).

Subset5-shot 10-shot
AU-PRAU-ROC AU-PRAU-ROC
candle53.286.665.892.7
capsules72.788.189.996.5
cashew80.890.986.494.4
chewinggum92.497.596.698.7
fryum72.186.577.090.5
macaroni178.391.785.595.6
macaroni259.085.666.289.9
pcb160.088.776.694.1
pcb262.185.965.688.7
pcb355.885.961.384.7
pcb472.491.470.592.0
pipe_fryum88.495.593.698.0
macro mean70.689.577.993.0
Table 6 — Per-subset anomaly segmentation results

Table 6 — Per-subset anomaly segmentation (pixel-level) results; each cell is the mean over the 5 sampling seeds (final-epoch EMA weights, 384×384 eval grid, official AUPR convention).

Subset5-shot 10-shot
AU-PRAU-ROC AU-PRAU-ROC
candle17.280.618.878.7
capsules39.086.570.096.2
cashew34.893.650.892.1
chewinggum79.097.187.498.0
fryum19.071.575.698.7
macaroni126.680.134.278.0
macaroni217.474.321.687.1
pcb112.484.355.583.3
pcb222.684.731.788.1
pcb323.884.830.189.2
pcb419.987.223.691.2
pipe_fryum44.792.574.894.5
macro mean29.784.847.889.6

4.4  Defect sizes study for anomaly segmentation

While the anomaly segmentation performance seems satisfactory in the above experiments, the model could still focus on a few large and easy defects but miss many small defective instances. To evaluate the performance on each defect scale individually, we divide the ground-truth defects by pixel area, using the model input size of 384×384 as the reference resolution: tiny under 16 px², small under 100 px², medium under 441 px², and large above 441 px².

Table 7 — High-shot pixel metrics per mask-area tier (the §2.1 tiers). One model per product class trained on the full official training split; each cell is the mean over the 12 classes. Scoring one tier ignores the pixels of every other tier.

TierAU-PRAU-ROC
tiny0.461.0
small12.478.8
medium39.989.7
large71.293.9
total70.590.7

Table 8 — Few-shot pixel metrics per mask-area tier (the §2.1 tiers). Each cell is the mean over the 12 product classes, averaged over the 5 sampling seeds (± std across seeds). Scoring one tier ignores the pixels of every other tier.

Tier5-shot 10-shot
AU-PRAU-ROC AU-PRAU-ROC
tiny0.6 ± 0.177.3 ± 1.40.4 ± 0.279.8 ± 2.0
small9.4 ± 1.584.5 ± 0.810.3 ± 0.887.2 ± 1.9
medium23.6 ± 2.785.2 ± 1.328.5 ± 2.289.1 ± 1.0
large25.4 ± 5.184.4 ± 2.944.8 ± 7.887.0 ± 4.1
total29.7 ± 4.084.8 ± 1.947.8 ± 6.189.6 ± 2.9

From Tables 7 and 8, we can observe that most of the contribution to the total scores comes from the large defects, which is expected. This is likely because both the training objective and the evaluation metrics are designed to reward predicting as many defective pixels as possible. However, performance drops rapidly as defect size decreases. If each defect is instead seen as a distinct instance, the model cannot find small defects as well as the total AU-PR or AU-ROC would suggest.

We can expect that a model with a higher input resolution may alleviate this issue — e.g., RF-DETR-Seg Max at 890×890, the largest variant in the family. However, treating every defect instance equally would still require redesigning the training objective.

References

  1. Isaac Robinson, Peter Robicheaux, Matvei Popov, Deva Ramanan, and Neehar Peri. RF-DETR: Real-time detection transformer. In International Conference on Learning Representations (ICLR), 2026.
  2. Paul Bergmann, Michael Fauser, David Sattlegger, and Carsten Steger. MVTec AD — a comprehensive real-world dataset for unsupervised anomaly detection. In IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), 2019.
  3. Yang Zou, Jongheon Jeong, Latha Pemula, Dongqing Zhang, and Onkar Dabeer. SPot-the-Difference self-supervised pre-training for anomaly detection and segmentation. In European Conference on Computer Vision (ECCV), 2022.
  4. Maxime Oquab, Timothée Darcet, Théo Moutakanni, et al. DINOv2: Learning robust visual features without supervision. Transactions on Machine Learning Research (TMLR), 2024.
  5. Peter Robicheaux, Matvei Popov, Anish Madan, Isaac Robinson, Joseph Nelson, Deva Ramanan, and Neehar Peri. Roboflow100-VL: A multi-domain object detection benchmark for vision-language models. In Advances in Neural Information Processing Systems (NeurIPS) Datasets and Benchmarks Track, 2025.
  6. Tsung-Yi Lin, Michael Maire, Serge Belongie, James Hays, Pietro Perona, Deva Ramanan, Piotr Dollár, and C. Lawrence Zitnick. Microsoft COCO: Common objects in context. In European Conference on Computer Vision (ECCV), 2014.

Appendix

Training schedule, per-epoch curves & COCO sanity check
  • Schedule: a fixed 30 epochs per subset, no early stopping, learning rates at half the official RF-DETR fine-tune recipe (5e-5 / 7.5e-5 encoder); everything else — effective batch 16, EMA, augmentation — follows the official recipe unchanged. Both come from a 50-epoch pilot at the stock recipe, whose curves converged by epoch ~20–25 and mildly degraded after. The deployed checkpoint is the best-on-validation segm mAP (EMA-aware) snapshot; the test set is never touched during training.
  • Per-epoch curves: the full metric set is recorded at every eval point (every 5 epochs + final), so the learning curves show the same quantities the final table reports. No test-split number ever feeds model selection.
  • Sanity check: before any VisA training, we ran the pretrained RF-DETR checkpoints on COCO val2017 through our exact evaluation path. Box and segmentation AP both land within 0.6 points of the published numbers (Table 9), so the data loading, model construction and evaluation code can be trusted. This step also caught a real bug: the framework’s default loader remaps COCO category ids, silently misaligning the pretrained classification head.

    Table 9 — Pretrained RF-DETR checkpoints re-evaluated on COCO val2017, against the published numbers.

    Sanity anchorAP50:95AP50
    RF-DETR-Small, box AP (ours)52.4771.32
    RF-DETR-Small, box AP (published)53.072.1
    RF-DETR-Seg-Small, segm AP (ours)42.5065.92
    RF-DETR-Seg-Small, segm AP (published)43.166.2