A Unified Model for Multi-class Anomaly Detection

Zhiyuan You, Lei Cui, Yujun Shen, Kai Yang, Xin Lu, Yu Zheng, Xinyi Le

Introduction: The Shift to Unified Anomaly Detection

In the world of unsupervised anomaly detection (AD), the standard operating procedure has been to train a dedicated model for every specific object or texture. For instance, if a factory line produces 15 different products, quality control typically requires 15 distinct models. This "one-class-one-model" approach is highly memory-intensive and struggles to scale in complex environments with high intra-class diversity.

Comparison between separate models and a unified model for anomaly detection.

The holy grail is a unified model—a single network capable of handling multiple classes simultaneously. However, building such a model introduces a major hurdle known as the "identity shortcut." Most AD methods rely on reconstruction: they learn to rebuild "normal" images so that when they encounter an "anomalous" image, the reconstruction fails, thereby highlighting the defect. Unfortunately, powerful neural networks (like standard MLPs or CNNs) often get "lazy" during multi-class training. They learn to simply copy the input to the output (an identity mapping). If a model can perfectly reconstruct an anomaly by just copying it, the anomaly becomes invisible to the system.

Methods: Overcoming the Identity Shortcut with UniAD

To tackle the identity shortcut while modeling a complex multi-class distribution, researchers propose UniAD. This novel framework utilizes a transformer-based architecture specifically designed to prevent the network from simply passing through input data.

The UniAD architecture featuring the Neighbor Masked Encoder, Layer-wise Query Decoder, and Feature Jittering.

The architecture relies on a pre-trained EfficientNet-b4 to extract features, which are then processed through three primary innovations:

  1. Layer-wise Query Decoder (LQD): While vanilla transformers use a single query embedding, UniAD injects learnable query embeddings into every layer of the decoder. These queries act as a fixed reference for what "normal" looks like, forcing the model to rely on learned distributions rather than just copying the input data.
  2. Neighbor Masked Attention (NMA): In standard attention mechanisms, a feature point can "see" itself and its immediate neighbors, making it too easy for the model to copy local pixels. NMA explicitly masks out a feature point and its surrounding neighborhood in the attention map. This forces the model to reconstruct a point based on distant, global context, effectively breaking the local leakage that leads to identity mapping.
  3. Feature Jittering (FJ): To further toughen the model, the authors add Gaussian noise to the input features during training. This turns the reconstruction task into a denoising task, urging the model to recover the "correct" normal message even when the input is corrupted.

Key Results and Insights

The researchers evaluated UniAD on two primary benchmarks: MVTec-AD (the industry standard containing 15 categories of textures and objects) and CIFAR-10 (adapted for a "many-versus-many" anomaly detection setting).

UniAD significantly outperformed existing state-of-the-art (SOTA) methods, especially in the challenging unified setting:

  • MVTec-AD (Unified): UniAD achieved a remarkable 96.5% AUROC for anomaly detection and 96.8% for localization. For comparison, the previous best competitor (DRAEM) dropped to 88.1% and 89.5% respectively when forced into a unified framework.
  • CIFAR-10 (Unified): UniAD reached a mean AUROC of 87.2%, surpassing the next best baseline by a substantial 8.3% margin without needing any auxiliary "outlier exposure" data.

Surprisingly, UniAD performs almost as well in the "unified" setting (one model for all 15 MVTec classes) as it does when trained separately for each class. This suggests that the model effectively learns a joint distribution of "normalcy" that transcends individual categories. By using one model instead of fifteen, UniAD offers a massive reduction in memory footprint, making it highly practical for deployment in multi-product industrial environments.

Limitations and Future Work

While UniAD represents a major step forward, the authors note a few areas for further exploration. The current model is "category-agnostic"—it doesn't know which class it is looking at. Incorporating class labels, if available, might further improve the model's ability to fit complex distributions. Additionally, while it excels at industrial objects and simple textures, its performance on highly cluttered or semantically complex scenes (like general "out-of-distribution" detection in the wild) remains an open question. Finally, like many automated surveillance and detection systems, there are potential privacy concerns depending on deployment contexts.

Summary updated

BibTeX
@inproceedings{you2022unified,
  author = {Zhiyuan You and Lei Cui and Yujun Shen and Kai Yang and Xin Lu and Yu Zheng and Xinyi Le},
  title = {{A Unified Model for Multi-class Anomaly Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=bMYU8_qD8PW},
}
Figure