Memory Mechanism for Unsupervised Anomaly Detection

Jiahao Li, Yiqiang Chen, Yunbing XingUAI 2023

Abstract

Unsupervised anomaly detection (UAD) is a binary classification task that detects anomalies in unseen samples given only unlabeled normal data. Reconstruction-based approaches are widely used, performing reconstruction error minimization on training data to learn normal patterns and quantifying the degree of anomalies by reconstruction errors on testing data. However, this approach tends to miss anomalies when the normal data contains multiple patterns, as the model generalizes unrestrictedly beyond normal patterns to include anomaly patterns. In this paper, we propose a memory mechanism that memorizes typical normal patterns through a capacity-controlled external differentiable matrix, limiting the model's generalization to anomalies. We achieved state-of-the-art performance on several public benchmarks.

The Overgeneralization Problem

Unsupervised Anomaly Detection typically relies on reconstruction-based models like Autoencoders (AEs). Theoretically, a model trained on normal data should fail to reconstruct an anomaly, yielding a high error that flags it. However, deep learning models often suffer from the Overgeneralization Problem (OGP), where they become too capable and perfectly reconstruct anomalies as well as normal data.

This issue is compounded by two primary real-world challenges:

  1. The Training Set Challenge: Normal data is rarely uniform and often contains multiple unlabeled patterns. Models struggle to define tight boundaries around these diverse patterns.
  2. The Test Set Challenge: "Semantic" anomalies may share low-level features with normal data but differ conceptually, making them difficult for overgeneralized models to distinguish.
The challenges of unsupervised anomaly detection: (a) semantic anomalies in the test set and (b) multi-pattern normal data in the training set.

The Memorizer Framework

To combat OGP, we introduce the Memorizer, an autoencoder framework integrated with a Memory Mechanism. Instead of passing the encoder's latent representation directly to the decoder, the Memorizer forces the representation through a capacity-controlled external memory matrix.

  • Capacity-Controlled Memory: A fixed-size differentiable matrix stores prototypical "normal" patterns learned during training.
  • Mapping-Sharing Strategy: A shared linear mapping pulls encoded inputs and the memory matrix into the same latent space to find the best matching normal prototypes.
  • Multi-Round Memory: The retrieval process is repeated for $R$ rounds to extract and consolidate invariant data patterns.

Unlike previous memory-augmented networks that rely on complex, dataset-specific penalty terms (like sparsity losses), the Memorizer achieves superior bounds purely through its architectural bottleneck.

Key Insights: Forced Bottlenecking

By forcing the decoder to reconstruct inputs using only a weighted sum of memorized normal patterns, the model loses the ability to reconstruct novel anomalous patterns. When presented with an anomaly, the model attempts to reconstruct it using "normal" building blocks. This results in a reconstruction that resembles a normal pattern rather than the anomaly, creating a massive, detectable reconstruction error.

The reconstruction model learns to reconstruct known normal patterns accurately while failing to reconstruct unknown anomalies, instead producing a normal-looking substitute that increases error.

Experimental Results

The Memorizer was evaluated on MNIST, Fashion-MNIST, and Kuzushiji-MNIST using a Remove-One-Class-Out (ROCO) protocol to simulate multi-pattern normal data.

  • Quantitative Performance: The Memorizer consistently achieved state-of-the-art results. For instance, on the MNIST ROCO-0 task, it achieved an AUROC of 97.79%, significantly outperforming Vanilla AEs (79.16%) and previous memory models like MemAE (86.16%).
  • Qualitative Sharpness: Kernel Density Estimation (KDE) plots confirm that the Memorizer creates a dramatically sharper boundary between normal and anomalous samples compared to standard architectures.

Conclusion

The Memorizer demonstrates that a well-designed architectural bottleneck is sufficient to prevent overgeneralization in UAD. By extracting common, invariant features while ignoring semantic redundancies, the memory mechanism establishes tighter boundaries for what is considered "normal," offering a robust solution for multi-pattern anomaly detection in real-world industrial applications.

Summary updated

BibTeX
@inproceedings{li2023memory,
  author = {Jiahao Li and Yiqiang Chen and Yunbing Xing},
  title = {{Memory Mechanism for Unsupervised Anomaly Detection}},
  booktitle = {Conference on Uncertainty in Artificial Intelligence},
  year = {2023},
  url = {https://openreview.net/forum?id=y79Ic8I15b},
}
Figure