Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly Detection

Dong Gong, Lingqiao Liu, Vuong Le, Budhaditya Saha, Moussa Reda Mansour, Svetha Venkatesh, Anton van den Hengel

Introduction

Standard autoencoders (AEs) are a staple in unsupervised anomaly detection. The premise is straightforward: a model trained only on normal data should fail to reconstruct anomalies, yielding a high error signal. However, deep neural networks are often too powerful, generalizing to abnormal inputs and reconstructing them with surprising accuracy. This paper introduces MemAE (Memory-augmented Autoencoder), which constrains the model's capacity by forcing it to reconstruct inputs using a fixed set of "normal" prototypical patterns.

The Generalization Problem in Anomaly Detection

In unsupervised settings, we typically train an AE to compress and reconstruct normal data. The expectation is that an anomaly—something the model hasn't seen—will result in a high reconstruction error.

Conceptual overview of MemAE: Abnormal inputs are mapped to normal memory prototypes, leading to significant reconstruction error.

As shown in the figure above, the critical flaw of standard AEs is their ability to interpolate. They often learn to reconstruct abnormal inputs (e.g., a car on a pedestrian path) almost as well as normal ones. If the reconstruction error for an anomaly is low, the system fails. MemAE addresses this by limiting the decoder's "vocabulary" to only normal building blocks.

Methods: The MemAE Architecture

The MemAE architecture augments the standard autoencoder with a memory module. It consists of three primary components:

  1. Encoder ($f_e(\cdot)$): Maps the input $x$ to a latent representation $z$.
  2. Memory Module: A matrix $M$ containing $N$ memory slots, each representing a prototypical feature vector of normal data learned during training.
  3. Decoder ($f_d(\cdot)$): Reconstructs the input from retrieved memory items.
The MemAE architecture featuring the memory module with attention-based addressing and hard shrinkage.

Sparse Addressing and Hard Shrinkage

The core innovation is the Memory Addressing mechanism. Instead of passing $z$ directly to the decoder, $z$ acts as a query to retrieve the most relevant items from memory $M$. To prevent the model from reconstructing anomalies by complex combinations of many memory items, the authors implement Hard Shrinkage and an Entropy Loss term. This enforces sparsity, ensuring the model uses only a few normal prototypes. During inference, an anomaly is forced to be represented by these normal components, resulting in a reconstruction that looks "normal" and thus differs significantly from the original input.

Datasets and Evaluation

The authors validated MemAE across diverse domains to prove its versatility:

  • Image Outliers: MNIST and CIFAR-10 (treated as one-class classification tasks).
  • Video Anomaly Detection: Real-world benchmarks including UCSD-Ped2, CUHK Avenue, and ShanghaiTech, involving complex scenes like fighting or unauthorized vehicles.
  • Cybersecurity: The KDDCUP99 dataset for network intrusion detection.

Key Insights and Results

  • Content Bottleneck: Unlike standard AEs that rely on spatial bottlenecks (hidden layer size), MemAE introduces a content bottleneck. It restricts the "vocabulary" available for reconstruction.
  • Performance: MemAE consistently outperformed standard AEs and VAEs. For instance, on the ShanghaiTech dataset, MemAE achieved an AUC of 0.712, compared to the standard AE's 0.697.
  • Qualitative Evidence: The authors visualized reconstructions of the digit "9" using a model trained only on the digit "5." A standard AE produced a recognizable "9," while MemAE produced a reconstruction resembling a "5," creating the high error necessary for detection.
  • Efficiency: The memory layer is highly efficient, adding negligible overhead (approx. 0.0004s per video frame).

Limitations and Future Work

While effective, MemAE requires manual tuning of the shrinkage threshold ($\lambda$) and the number of memory slots ($N$). Future research could explore using the addressing weights directly as an anomaly score or integrating the memory module into more complex architectures like GANs or temporal RNNs for enhanced video analysis.

Summary updated

BibTeX
@inproceedings{gong2019memorizing,
  author = {Dong Gong and Lingqiao Liu and Vuong Le and Budhaditya Saha and Moussa Reda Mansour and Svetha Venkatesh and Anton van den Hengel},
  title = {{Memorizing Normality to Detect Anomaly: Memory-augmented Deep Autoencoder for Unsupervised Anomaly Detection}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2019},
  doi = {10.1109/iccv.2019.00179},
}
Figure