ADTR: Anomaly Detection Transformer with Feature Reconstruction

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

TL;DR

ADTR (Anomaly Detection TRansformer) rethinks unsupervised anomaly detection by shifting the focus from reconstructing raw pixels to reconstructing high-level semantic features. By utilizing a Transformer architecture with a learnable query embedding, the model effectively avoids the "identical mapping" trap—where models accidentally learn to reconstruct anomalies too well—resulting in state-of-the-art performance on major benchmarks like MVTec-AD.

What Problem Does This Paper Address?

In industrial settings, anomalies are rare, meaning models must often learn what is "normal" using only healthy samples. Traditional approaches frequently use CNN-based Auto-Encoders to reconstruct input images, calculating an anomaly score based on the reconstruction error. However, these methods face two major hurdles:

  1. Semantic Poverty: Raw pixels lack distinguishable semantic information. A normal region and an anomalous region might have similar pixel values but different textures or structural meanings that a pixel-level model misses.
  2. The Identical Mapping Shortcut: CNNs are exceptionally good at generalizing. Paradoxically, they often become too good, reconstructing anomalous regions just as accurately as normal ones. If the reconstruction is perfect for both, the anomaly remains hidden.

ADTR addresses these by moving the reconstruction target into the feature space and using a Transformer to break the "identical mapping" tendency.

Methods

The ADTR pipeline consists of three main stages:

  • Feature Embedding: Instead of raw pixels, the model uses a frozen, pre-trained CNN backbone (EfficientNet-B4) to extract multi-scale features. Features from different layers are resized and concatenated to capture both fine-grained local details and global structural patterns.
  • Transformer Reconstruction: The core innovation is using a Transformer to reconstruct these feature tokens. The authors argue that the Transformer decoder's architecture—specifically its reliance on a learnable query embedding—acts as a bottleneck. Unlike a CNN that might simply pass through information, the Transformer must map the learned "normal" queries to the input features. This makes it much harder for the model to reconstruct features it hasn't seen during training (i.e., anomalies).
  • Flexible Loss Functions: The authors introduce a "push-pull" loss strategy. In the standard case, the model is trained to "pull" reconstructions toward normal features. If a few anomalies are available (or synthetic ones are created), a novel loss function "pushes" the reconstruction of those anomalies away from the original features, further widening the detection gap.
Fig. 1: (a) CNN-based pixel reconstruction methods tend to reconstruct both normal samples and anomalies well, making them still hard to distinguish. Also, the pixel values contain indistinguishable semantic information. (b) Our method reconstructs features with distinguishable semantic information. Besides, the adoption of transformer limits the reconstruction of anomalies.

Datasets

The model was evaluated on two primary benchmarks:

  • MVTec-AD: The gold standard for industrial anomaly detection, containing 15 categories of objects and textures with real-world defects.
  • CIFAR-10: A classic image classification dataset adapted for anomaly detection by treating one class as "normal" and others as "anomalous."
  • Synthetic Data: The authors also experimented with "confetti noise"—simple synthetic anomalies added to normal samples—to test the model's performance when some anomalous data is available during training.

Key Insights and Ideas

  • Architecture as a Regularizer: The most striking insight is that the Transformer's attention mechanism is inherently resistant to learning identity functions. The authors' ablation studies showed that removing the attention layer or the query embedding caused performance to drop to CNN-like levels, confirming that the Transformer architecture itself helps prevent the "identical shortcut."
  • Feature Space is Better: Reconstructing features extracted from a model pre-trained on ImageNet provides a "semantic head start." These features already contain boundaries and textures that are more distinguishable than raw RGB values.
  • Multi-Scale Sensitivity: By concatenating features from multiple CNN layers, the model gains different "receptive fields," making it sensitive to both tiny scratches (local) and missing components (global).
Fig. 2: Overview of our method. (a) Embedding: a pre-trained CNN backbone is applied to extract the multi-scale features. (b) Reconstruction: a transformer is utilized to reconstruct the feature tokens with an auxiliary learnable query embedding. (c) Comparison: our approach is compatible with both normal- sample-only case and anomaly-available case. The anomaly score maps are obtained through the differences between extracted and reconstructed features.

Key Results

ADTR achieves impressive quantitative gains over previous methods:

  • MVTec-AD: Achieved a pixel-level AUROC (for localization) of 97.2% and an image-level AUROC (for detection) of 96.4% using only normal samples. This outperformed strong baselines like SPADE and KDAD.
  • CIFAR-10: In the one-class classification task, ADTR surpassed the previous state-of-the-art (KDAD) by a significant margin of 7.5% (94.7% vs 87.2% AUROC).
  • Qualitative Success: The model proved capable of detecting subtle logical anomalies, such as a "Metal Nut" that was simply flipped over—a defect with no obvious color or texture change that often baffles simpler models.

Limitations and Future Work

While ADTR shows superior performance, the paper leaves a few areas for further exploration:

  • Backbone Dependency: The method relies on a pre-trained CNN. Its performance in domains very different from natural images (like medical imaging or satellite data) might require domain-specific pre-training.
  • Computational Overhead: Transformers, especially with multi-scale feature tokens, can be more computationally expensive than simple convolutional auto-encoders.
  • Future Directions: The authors suggest that the performance could be further bolstered by more sophisticated synthetic anomaly generation techniques beyond simple confetti noise.

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