ADTR: Anomaly Detection Transformer with Feature Reconstruction

Zhiyuan You, Kai Yang, Wenhan Luo, Lei Cui, Yu Zheng, Xinyi Le

Introduction

Unsupervised anomaly detection (UAD) is a critical task in industrial quality control and computer vision, where the objective is to identify samples that deviate from a learned distribution of "normal" data. Traditionally, this has been approached through reconstruction-based methods, such as Convolutional Auto-Encoders (CAEs). These models are trained to reconstruct normal samples; at inference time, a high reconstruction error indicates an anomaly. However, traditional methods often struggle with two fundamental issues: the semantic gap of pixel-level reconstruction and the "identical mapping shortcut," where models inadvertently learn to reconstruct anomalies as well as normal data.

This paper introduces ADTR (Anomaly Detection TRansformer), a novel framework that shifts the reconstruction target from raw pixels to high-level semantic features. By utilizing a Transformer architecture with learnable query embeddings, ADTR effectively breaks the local reconstruction shortcuts inherent in CNNs, setting new benchmarks for accuracy and localization.

The Problem: Shortcuts and Semantic Gaps

Existing CNN-based reconstruction methods face significant hurdles. First, pixel-level reconstruction lacks semantic context; a minor scratch on a complex texture might be indistinguishable from noise at the pixel level. Second, CNNs are inherently biased toward local reconstruction. Because of their inductive bias, they often generalize too well, successfully reconstructing anomalous regions by simply "copy-pasting" local textures. When a model can reconstruct an anomaly, the resulting low error score leads to a failure in detection.

Methodology

ADTR addresses these challenges through three primary innovations:

1. Feature Reconstruction

Instead of attempting to reconstruct raw pixels, ADTR reconstructs features extracted from a frozen, pre-trained CNN backbone (specifically EfficientNet-B4). These features encapsulate rich semantic information across multiple scales (layers 1 through 5). This allows the model to be sensitive to both fine-grained defects (like cracks) and large-scale structural irregularities (like missing components).

2. Transformer with Learnable Queries

The core of the ADTR architecture is a Transformer Encoder-Decoder. Unlike a standard CNN, the ADTR decoder utilizes an auxiliary learnable query embedding. This architectural constraint is vital: the Transformer must use its learned internal representation of "normalcy" to reconstruct the feature tokens. This prevents the model from relying on local pixel-copying shortcuts, making it significantly harder to reconstruct features that were never seen during the training phase.

3. Unified Loss Framework

ADTR introduces a flexible loss framework comprising three components ($L_{norm}$, $L_{px}$, and $L_{img}$). This allows the model to adapt to various data availability scenarios:

  • Normal-only: Standard unsupervised learning using only healthy samples.
  • Pixel-level labels: Leveraging a small subset of annotated anomalies to sharpen localization.
  • Image-level labels: Utilizing binary "good/bad" labels to refine the feature space even without precise defect masks.

Experimental Results

ADTR was evaluated on the MVTec-AD and CIFAR-10 datasets, representing industrial and semantic anomaly detection tasks, respectively.

MVTec-AD Performance

On the MVTec-AD benchmark, ADTR achieved state-of-the-art (SOTA) results, reaching an image-level AUROC of 96.4% and a pixel-level AUROC of 97.2%. The model demonstrated a superior ability to generate precise anomaly heatmaps, accurately localizing structural misplacements and subtle stains that previous models like SPADE or KDAD often blurred.

CIFAR-10 and Semantic Detection

In a "one-class" classification setting on CIFAR-10, ADTR achieved a mean AUROC of 94.7%. This represents a 7.5% improvement over the previous best reconstruction-based method (KDAD). This result highlights the model's ability to distinguish between different semantic classes (e.g., identifying a "dog" as an anomaly when trained only on "cars"), a task where pixel-based methods typically fail.

Key Insights

An ablation study confirmed that the Transformer's query mechanism is the primary driver of performance. Removing the learnable query embedding caused a significant drop in detection accuracy, proving that the Transformer's specific data-processing bottleneck is fundamentally better suited for anomaly detection than standard convolutional architectures. Furthermore, the use of a pre-trained backbone allows the model to understand "logical" anomalies—such as an object being oriented incorrectly—even if the local textures appear normal.

Limitations and Future Directions

Despite its success, ADTR has limitations. Its performance is partially dependent on the pre-trained backbone; if the target domain differs drastically from the ImageNet distribution (e.g., specific medical imagery), feature extraction may be less effective. Additionally, the computational cost of Transformers is higher than that of simple Auto-Encoders, which may impact real-time deployment in high-speed production lines. Future work may involve self-supervised pre-training specifically designed for anomaly detection to further enhance feature sensitivity.

Conclusion

ADTR represents a significant step forward in unsupervised anomaly detection. By combining the semantic power of pre-trained features with the structural constraints of a Transformer decoder, it overcomes the long-standing "identical mapping" problem. Its robust performance across both industrial and semantic datasets makes it a versatile tool for the next generation of automated inspection systems.

Summary updated

BibTeX
@inproceedings{you2022adtr,
  author = {Zhiyuan You and Kai Yang and Wenhan Luo and Lei Cui and Yu Zheng and Xinyi Le},
  title = {{ADTR: Anomaly Detection Transformer with Feature Reconstruction}},
  booktitle = {ICONIP},
  year = {2022},
  url = {https://openreview.net/forum?id=s7t87Woz7g},
}
Figure