DSR - A dual subspace re-projection network for surface anomaly detection

Vitjan Zavrtanik, Matej Kristan, Danijel Skocaj

Introduction

In industrial manufacturing, identifying surface defects is a critical component of quality assurance. However, the rarity of defects makes supervised learning impractical, as collecting a balanced dataset of anomalies is often impossible. Consequently, the field has shifted toward unsupervised anomaly detection (AD), where models are trained exclusively on defect-free samples.

While current state-of-the-art methods have made significant strides, they often struggle with "near-in-distribution" anomalies—subtle defects like slight scratches or minor discolorations that closely resemble the normal texture of an object. DSR (Dual Subspace Re-projection) addresses this by introducing a novel framework that generates realistic anomalies within a quantized latent feature space, eliminating the need for external datasets and significantly improving localization accuracy.

The Challenge of Near-In-Distribution Anomalies

Most unsupervised AD methods rely on reconstructing an image and measuring the error between the input and the reconstruction. To train these models to recognize defects, researchers often use synthetic anomalies created by pasting "noise" from external datasets (like ImageNet) onto normal images.

This approach has a fundamental flaw: the synthetic anomalies are often "out-of-distribution," meaning they look nothing like the actual industrial surfaces. As a result, models become adept at finding obvious, high-contrast defects but remain blind to subtle, near-in-distribution variations. DSR seeks to bridge this gap by simulating defects that are semantically and structurally similar to the target object.

Methodology

DSR moves beyond simple image-level reconstruction through three primary innovations: a quantized latent space, a dual-decoder architecture, and a feature-level anomaly generation strategy.

1. Quantized Latent Space

The network employs a Vector Quantized (VQ) encoder to project input images into a discrete feature space. Instead of continuous values, the image is represented as a grid of "codebook" vectors. This discretization forces the model to learn the underlying structural patterns of natural textures, preventing the "identity mapping" trap where an autoencoder simply passes pixels through without understanding the data distribution.

2. Dual-Decoder Architecture

DSR utilizes two distinct decoders to identify deviations from the norm:

  • General Decoder: This component is pre-trained on ImageNet to reconstruct any natural image with high fidelity. Its role is to provide a high-quality reconstruction of the input, including any anomalies present.
  • Object-Specific Decoder: This decoder uses a "subspace restriction module" to map latent features back to the "normal" appearance of the specific object being inspected. It is designed to "fix" anomalies, effectively re-projecting defective regions back into the subspace of normal features.

By comparing the outputs of these two decoders using a U-Net module, the system can generate a precise anomaly map.

3. Latent Space Anomaly Generation

Rather than using external images to simulate defects, DSR generates training anomalies by sampling from its own learned codebook. It replaces normal feature vectors with their "near neighbors" in the latent space. This creates subtle, realistic deviations that force the model to learn the fine boundary between a normal surface and a defective one. This feature-level augmentation is superior to image-level methods (like CutPaste) because it allows the model to learn semantic deviations rather than just reacting to sharp edges or color mismatches.

Experimental Evaluation

The authors evaluated DSR on two primary benchmarks:

  • KSDD2 (Kolektor Surface-Defect Dataset 2): A challenging real-world dataset featuring subtle defects from industrial production lines.
  • MVTec AD: The industry-standard benchmark containing 15 different object and texture classes.

Additionally, ImageNet was used for the initial training phase to help the general decoder learn the manifold of natural images.

Key Results and Insights

DSR demonstrated significant performance gains over existing methods, particularly on complex industrial datasets:

  • State-of-the-Art Localization: On the KSDD2 dataset, DSR improved image-level Average Precision (AP) by 7.9 percentage points and achieved a massive 35% improvement in pixel-level localization AP compared to the previous leading method, DRAEM.
  • MVTec AD Performance: DSR achieved an average AUROC of 98.2%, showing particular strength in classes with complex deformations, such as "transistor" and "screw."
  • Real-Time Efficiency: Despite the dual-decoder setup, the model operates at 58 FPS, making it highly suitable for real-time industrial deployment.
  • Low-Shot Flexibility: While primarily unsupervised, DSR can incorporate a small number of labeled anomalies, where it significantly outperforms specialized supervised models.

Conclusion

The success of DSR highlights the power of subspace restriction. The core insight is that one does not need to see every possible defect to identify them; rather, by accurately defining the "subspace" of what is normal, any feature that falls outside that boundary—even slightly—can be identified and re-projected.

While the current near-neighbor sampling strategy is highly effective, future work may explore more complex or learned feature-sampling methods to further refine the detection of the most difficult near-in-distribution cases. DSR represents a significant step forward in making unsupervised anomaly detection robust enough for the nuances of real-world industrial inspection.

Summary updated

BibTeX
@inproceedings{zavrtanik2022dsr,
  author = {Vitjan Zavrtanik and Matej Kristan and Danijel Skocaj},
  title = {{DSR - A dual subspace re-projection network for surface anomaly detection}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-19821-2\_31},
}
Figure