MambaAD: Exploring State Space Models for Multi-class Unsupervised Anomaly Detection

Haoyang He, Yuhu Bai, Jiangning Zhang, Qingdong He, Hongxu Chen, Zhenye Gan, Chengjie Wang, Xiangtai Li, Guanzhong Tian, Lei Xie

Abstract

Industrial anomaly detection (AD) has traditionally relied on single-class models, which are difficult to scale in real-world manufacturing environments. Multi-class AD offers a more practical alternative but faces a fundamental trade-off between the local efficiency of Convolutional Neural Networks (CNNs) and the global context of Transformers. This paper introduces MambaAD, the first framework to apply State Space Models (SSMs) to multi-class unsupervised AD. MambaAD utilizes a pyramid-structured auto-encoder with a novel Locality-Enhanced State Space (LSS) module and Hilbert scanning to capture both global and local features with linear computational complexity. Evaluated across six major benchmarks, MambaAD achieves state-of-the-art performance while maintaining a significantly more lightweight computational profile than previous diffusion or transformer-based models.

Introduction: The Shift to Multi-Class Anomaly Detection

In industrial visual inspection, Anomaly Detection (AD) is critical for identifying defects such as scratches, cracks, or missing components. Traditionally, researchers employed a "single-class" setup, training a unique model for every product type. However, this approach is inefficient for factories with thousands of product lines.

The shift toward multi-class AD—where a single model handles multiple categories—introduces a "capacity" problem. CNNs are computationally efficient but struggle with long-range dependencies, while Transformers offer a global receptive field but suffer from quadratic computational complexity ($O(N^2)$). MambaAD addresses this by leveraging Mamba, a selective State Space Model that provides global receptive fields with linear complexity ($O(N)$).

Comparison of architectural paradigms for anomaly detection. MambaAD achieves a global+local receptive field with linear complexity O(N).

Methodology: The MambaAD Framework

MambaAD is built upon a pyramid-structured auto-encoder architecture. It employs a pre-trained, frozen CNN (ResNet34) as an encoder to extract multi-scale features, which are then processed by a novel Mamba-based decoder.

The overall architecture of MambaAD, featuring a frozen pre-trained encoder and a Mamba-based decoder with Locality-Enhanced State Space (LSS) modules.

Key Innovations

  1. Locality-Enhanced State Space (LSS) Module: While Mamba excels at capturing global context, it can overlook fine-grained local textures essential for detecting small defects. The LSS module integrates Mamba-based blocks in parallel with multi-kernel depth-wise convolutions (5x5 and 7x7), allowing the model to simultaneously process broad structural information and minute local details.
  2. Hybrid State Space (HSS) Block & Hilbert Scanning: To adapt the 1D sequence processing of Mamba to 2D images, the authors utilize Hilbert Scanning. This space-filling curve preserves spatial locality more effectively than standard row-by-row scanning. By employing eight different scanning directions, the model ensures it captures spatial relationships from multiple perspectives.

Experimental Evaluation

The authors evaluated MambaAD on six diverse datasets, including the gold-standard MVTec-AD and VisA, as well as the large-scale Real-IAD dataset (30 categories, 150,000 images).

Key Results

  • State-of-the-Art Accuracy: MambaAD achieved a 98.6% AU-ROC at the image level and 97.7% at the pixel level on MVTec-AD. On the challenging Real-IAD dataset, it reached 86.3% AU-ROC, demonstrating strong scalability.
  • Computational Efficiency: MambaAD maintains a lightweight profile with approximately 25.7M parameters and 8.3 GFLOPs. Remarkably, it outperforms DiAD (a diffusion-based model) while requiring only 1/50th of the parameters and FLOPs.
  • Multi-Scale Reconstruction: By reconstructing features across the pyramid levels, the model effectively detects both large-scale structural anomalies and microscopic surface defects.

Conclusion

MambaAD represents a significant step forward in multi-class unsupervised anomaly detection. By successfully integrating State Space Models into the AD pipeline, the framework breaks the traditional trade-off between receptive field size and computational complexity. While the authors suggest that even more lightweight designs may be possible for extreme edge-computing scenarios, MambaAD currently sets a new benchmark for efficiency and accuracy in industrial visual inspection.

Summary updated

BibTeX
@inproceedings{he2024mambaad,
  author = {Haoyang He and Yuhu Bai and Jiangning Zhang and Qingdong He and Hongxu Chen and Zhenye Gan and Chengjie Wang and Xiangtai Li and Guanzhong Tian and Lei Xie},
  title = {{MambaAD: Exploring State Space Models for Multi-class Unsupervised Anomaly Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=8VKxTlnejE},
}
Figure