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

TL;DR

MambaAD is the first framework to apply Mamba State Space Models (SSMs) to multi-class unsupervised anomaly detection. By combining global Mamba-based modeling with local convolutional features, it achieves state-of-the-art accuracy across multiple benchmarks while being significantly more computationally efficient than Transformer-based alternatives.

What Problem Does This Paper Address?

Industrial visual Anomaly Detection (AD) is a cornerstone of smart manufacturing, helping to identify defects in products ranging from microchips to textiles. Traditionally, researchers have used a "single-class" setting, training a dedicated model for every single type of object. This is incredibly inefficient as the number of product categories grows.

"Multi-class" AD aims to train one unified model for all categories. However, this presents a major architectural challenge:

  1. CNNs are efficient but struggle to capture long-range dependencies (global context).
  2. Transformers capture global context perfectly but suffer from quadratic computational complexity, making them too slow and memory-hungry for high-resolution, multi-scale feature processing.
Figure 1: Compared with (a) local CNN-based RD4AD [12] and (b) global Transformer-based UniAD [47], ours MambaAD with linear complexity is capable of integrating the advantages of both global and local modeling, and multi-scale features endow it with more refined prediction accuracy.

As shown in Figure 1, MambaAD seeks to bridge this gap by leveraging the linear complexity of State Space Models to integrate both global and local modeling across multiple scales.

Methods

The authors introduce MambaAD, a pyramidal auto-encoder framework consisting of a pre-trained CNN encoder and a novel Mamba-based decoder. The core innovation lies in the Locality-Enhanced State Space (LSS) module.

Figure 2: Overview of the proposed MambaAD, which employs pyramidal auto-encoder framework to reconstruct multi-scale features by the proposed efficient and effective Locality-Enhanced State Space (LSS) module. Specifically, each LSS consists of: 1) cascaded Hybrid State Space (HSS) blocks to capture global interaction; and 2) parallel multi-kernel convolution operations to replenish local information. Aggregated multi-scale reconstruction error serves as the anomaly map for inference.

Key Components:

  • Locality-Enhanced State Space (LSS) Module: Instead of relying solely on Mamba, the LSS module processes features through two parallel branches: a series of Hybrid State Space (HSS) blocks for global interaction and multi-kernel depth-wise convolutions for local detail.
  • Hybrid State Space (HSS) Block: To adapt 1D Mamba sequences to 2D images, the HSS block uses Hybrid Scanning (HS). It explores five scanning methods (Sweep, Scan, Z-order, Zigzag, and Hilbert) across eight directions.
  • Hilbert Scanning: The authors found that Hilbert curves are particularly effective for industrial images because they maintain spatial locality better than simple raster scans, especially for objects centrally located in the frame.
  • Multi-Scale Reconstruction: The model reconstructs features at three different scales. The final anomaly map is generated by summing the reconstruction errors across these scales, allowing the model to catch both tiny scratches and large structural defects.

Datasets

The model was evaluated on six diverse anomaly detection datasets:

  • MVTec-AD: The industry standard with 15 categories of objects and textures.
  • VisA: Features complex structures and multiple instances of objects.
  • Real-IAD: A large-scale dataset with 30 categories and 150k high-resolution images.
  • MVTec-3D, Uni-Medical, and COCO-AD: Used to further demonstrate the model's versatility across 3D data, medical imaging, and general-purpose benchmarks.

Key Insights and Ideas

  • The Best of Both Worlds: Ablation studies showed that the "Local + Global" approach in the LSS module outperformed using either branch alone. The CNN branch provides the "fine-grained" details, while the Mamba branch provides the "big picture."
  • Linear Scaling is the Secret Sauce: Because Mamba scales linearly with sequence length, MambaAD can afford to process features at multiple scales simultaneously. Transformers are often confined to the smallest (lowest resolution) feature maps to avoid memory overflow.
  • Scanning Matters: Moving beyond simple four-direction scans to eight-direction Hilbert scanning provided a measurable boost in performance, proving that how you "flatten" an image into a sequence significantly impacts an SSM's ability to learn spatial relationships.

Key Results

MambaAD achieved State-of-the-Art (SoTA) results across the board:

  • MVTec-AD: Reached 98.6% AU-ROC at the image level, outperforming the previous leader, DiAD.
  • Efficiency: Compared to the diffusion-based DiAD, MambaAD achieved better results with only 1/50th of the parameters and FLOPs (25.7M params vs. 1331.3M).
  • Scalability: On the massive Real-IAD dataset, MambaAD maintained high performance (86.3% image-level AU-ROC), demonstrating its robustness for large-scale industrial applications.

Limitations and Future Work

While MambaAD is a significant step forward, the authors note that the model is still not "efficient enough" for the most extreme edge-computing scenarios. They suggest that future research should focus on even more lightweight designs. Additionally, this study marks an initial attempt to apply Mamba to AD; further exploration into different SSM variants or hybrid architectures could yield even higher precision.

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