Foundation Visual Encoders Are Secretly Few-Shot Anomaly Detectors

Guangyao Zhai, Yue Zhou, Xinyan Deng, Lars Heckler, Nassir Navab, Benjamin Busam

TL;DR

Industrial foundation models "secretly" encode anomaly information because the size of an anomalous region directly correlates with its feature distance from normal images in the embedding space. By leveraging this property, the authors introduce FOUNDAD, a lightweight, few-shot anomaly detector that trains a simple non-linear projector to map anomalous features back onto a learned "normal image manifold." This approach achieves state-of-the-art multi-class anomaly detection using up to 13× fewer parameters than competing methods, entirely eliminating the need for complex text prompts.

What Problem Does This Paper Address?

In industrial safety inspection, detecting anomalies (like scratches, cracks, or missing components) using only a few normal examples—known as Few-Shot Anomaly Detection (FSAD)—is incredibly valuable. Collecting large, fully labeled datasets of defects is impractical because defects are rare and unpredictable.

While large-scale foundation models (e.g., DINOv2, CLIP) have revolutionized computer vision, adapting them to FSAD typically requires complex multi-model pipelines (combining DINO, CLIP, and SAM) or intricate hand-crafted text prompts to guide the model. Furthermore, traditional methods struggle with multi-class settings, where a single model must detect anomalies across entirely different categories (e.g., screws, cables, and toothbrushes) simultaneously.

This paper addresses these complexities by asking a fundamental question: Can we perform highly accurate, multi-class few-shot anomaly detection using purely visual features from a single frozen foundation encoder?

Methods

The authors introduce FOUNDAD (Foundation Anomaly Detector), which operates entirely within the latent space of a frozen foundation model (like DINOv3).

FOUNDAD Training and Inference Pipeline

The core architecture consists of three main steps:

  1. Anomaly Synthesis: To train the model without real defect data, the framework uses a modified CutPaste technique. It cuts patches from normal images and pastes them onto foreground regions (isolated via adaptive thresholding) to simulate structural anomalies.
  2. Visual Manifold Projection: Normal images ($I_r$) and synthesized anomalous images ($I_s$) are passed through identical, weight-shared foundation encoders to extract patch embeddings ($f_r$ and $f_s$).
  3. The Manifold Projector ($\phi$): The authors train a lightweight, 6-layer self-attention Vision Transformer (ViT) projector. Its sole job is to take the anomalous embedding $f_s$ and project it back onto the "natural image manifold," outputting an estimated normal feature $f_r^*$. The network minimizes the $L2$ distance between $f_r^*$ and the true normal feature $f_r$.

During inference, a test image is encoded and passed through the projector. The patch-level anomaly score is simply the squared $L2$ distance between the original embedding and its projected counterpart. If the projector significantly alters a patch's features to make it look "normal," that patch is flagged as anomalous.

Datasets

The approach was evaluated on two standard, highly challenging industrial anomaly detection benchmarks:

  • MVTec-AD: Contains 5,354 high-resolution images across 15 categories (5 textures, 10 objects), featuring real-world defects like contamination and structural deformations.
  • VisA: Contains 10,821 images across 12 object categories, presenting complex challenges like multi-instance objects and diverse anomaly patterns.

Key Insights and Ideas

  • The "Secret" Correlation: The authors discovered that foundation models inherently map normal natural images to a tight manifold. When an anomaly is introduced, its embedding drifts away from this manifold. Crucially, the $L2$ distance of this drift scales monotonically with the pixel area of the anomaly.
Figure 2: Correlation of Anomaly Area with Feature Distance. Two foundation encoders under different paradigms are shown. Upper left/right: Real images with corresponding synthetic and real anomalies. Lower left/right: Coloured PCA visualizations of their embedded features using SigLIP (Zhai et al., 2023b) (left) and DINOv2 (Oquab et al., 2024) (right). Center: L2-feature distance of embeddings for synthetic anomalies of increasing pixel amount on a real image. A clear correlation is visible for both foundation models.
  • Text Prompts are Optional: Unlike recent trends that rely on vision-language models (like CLIP) and textual descriptions of defects, FOUNDAD proves that pure visual features contain more than enough geometric and semantic information to isolate anomalies.
  • Goldilocks Layers: Not all layers in a foundation model are equal for anomaly detection. Testing across DINOv3 layers revealed that mid-to-late layers (specifically Layer 10) provide the optimal balance between high-level semantic understanding and fine-grained spatial precision.
Figure 6: Comparison of performance using different layers of DINOv3 in a 1-shot setting on MVTec-AD.

Key Results

  • State-of-the-Art Performance: In the highly restrictive 1-shot multi-class setting, FOUNDAD outperformed all baselines. On MVTec-AD, it achieved an Image-AUROC of 96.1% and a Per-Region-Overlap (PRO) score of 92.8%. On VisA, it achieved a near-perfect Pixel-AUROC of 99.7%.
  • Extreme Parameter Efficiency: FOUNDAD introduces only 11.8M trainable parameters. When paired with a DINOv3-ViT-B backbone, the entire system uses 97.8M parameters. This is roughly 10× to 13× smaller than competing heavyweights like IIPAD (1.0B) and LogSAD (1.3B), while delivering superior accuracy.
Figure 4: Bubble chart of AUROC results across dif- ferent methods, averaged over MVTec-AD and VisA from Table 1. The smaller the circle is, the fewer pa- rameters it has.
  • Clean Visualizations: Qualitatively, FOUNDAD generates highly precise anomaly heatmaps with significantly less background noise than prompt-based alternatives.
Figure 5: Qualitative comparison with few-shot baselines in 1-shot setting. We directly compare our results with the ones cropped from IIPAD (Lv et al., 2025).

Limitations and Future Work

Despite its strong performance, the authors note a few scenarios where FOUNDAD can falter:

  • Spatial Orientation: Because the projector lacks an explicit spatial alignment mechanism, it struggles if a normal object appears in an entirely different orientation (e.g., a rotated screw) during testing.
  • Non-Generative Constraints: The projector is non-generative (it maps features rather than reconstructing pixels). This limits its ability to cleanly segment complex morphological defects, such as missing pins on an electronic transistor.
  • Illumination Sensitivity: Severe exposure or lighting variations can cause normal regions to drift away from the learned manifold, occasionally leading the model to misclassify background artifacts or stains as anomalies.

Summary updated

BibTeX
@inproceedings{zhai2026foundation,
  author = {Guangyao Zhai and Yue Zhou and Xinyan Deng and Lars Heckler and Nassir Navab and Benjamin Busam},
  title = {{Foundation Visual Encoders Are Secretly Few-Shot Anomaly Detectors}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=YRrlJ8oVEH},
}
Figure