ALGAN: Anomaly Detection by Generating Pseudo Anomalous Data via Latent Variables

Hironori Murase, Kenji Fukumizu

Abstract

In many anomaly detection tasks, where anomalous data rarely appear and are difficult to collect, training using only normal data is important. Although it is possible to manually create anomalous data using prior knowledge, they may be subject to user bias. In this paper, we propose an Anomalous Latent variable Generative Adversarial Network (ALGAN) in which the GAN generator produces pseudo-anomalous data as well as fake-normal data, whereas the discriminator is trained to distinguish between normal and pseudo-anomalous data. This differs from the standard GAN discriminator, which specializes in classifying two similar classes. The training dataset contains only normal data; the latent variables are introduced in anomalous states and are input into the generator to produce diverse pseudo-anomalous data. We compared the performance of ALGAN with other existing methods on the MVTec-AD, Magnetic Tile Defects, and COIL-100 datasets. The experimental results showed that ALGAN exhibited an AUROC comparable to those of state-of-the-art methods while achieving a much faster prediction time.

Introduction

Anomaly detection is a critical "needle in a haystack" problem in visual inspection and medical diagnostics. Because anomalous data (such as cracks in tiles or tumors in X-rays) is rare and difficult to collect, most models must be trained using only "normal" data.

Standard Generative Adversarial Networks (GANs) have been applied to this task, but they suffer from a fundamental limitation: the discriminator is typically trained to distinguish between "real-normal" and "fake-normal" data. As training progresses, these two classes become nearly identical, meaning the discriminator fails to learn a robust decision boundary for identifying true anomalies—it simply becomes a critic of the generator's realism. ALGAN aims to resolve this by explicitly providing the discriminator with examples of what "bad" data might look like, without requiring real anomalous samples.

Methodology

The core innovation is the Anomalous Latent variable Generative Adversarial Network (ALGAN). The framework introduces two types of "pseudo-anomalous" data during the training phase to force the discriminator to learn a tight decision boundary around real normal data.

ALGAN architecture overview: (a) training phase with normal and pseudo-anomalous data; (b) inference phase using the discriminator.

As shown in the architecture above, ALGAN utilizes two primary sources for pseudo-anomalies:

  1. Fake-Anomalous Data ($x'_a$): While normal GANs sample latent variables from a standard distribution $N(0, I)$, ALGAN also samples from an "anomalous" latent distribution with significantly higher variance ($N(0, \sigma^2 I)$, where $\sigma=4$). This forces the generator to produce "off-model" data—distorted versions of the normal data.
  2. Buffered Data ($\hat{x}$): The model stores samples generated during the early, "immature" stages of training. These noisy, unrealistic samples serve as another proxy for anomalies.

The discriminator is then trained to classify real-normal data as "Normal" and everything else—fake-normal, fake-anomalous, and buffered data—as "Anomalous."

Generating Pseudo-Anomalies via Latent Space

By pushing latent variables into high-entropy regions (the "tails" of the distribution), the generator naturally produces outputs that look almost like the target but are fundamentally "wrong."

Visual comparison of normal latent outputs versus pseudo-anomalous latent outputs across multiple MVTec-AD categories.

This approach allows the model to define the boundaries of "normality" more effectively than methods relying solely on reconstruction error. Because ALGAN uses the discriminator's raw output as the anomaly score, it avoids the iterative optimization steps required by other GAN-based methods, leading to significant performance gains.

Experimental Results

The authors evaluated ALGAN on three primary benchmarks: MVTec-AD, Magnetic Tile Defects (MTD), and COIL-100.

  • Inference Speed: ALGAN-image achieved a prediction time of 10.6 ms per image, making it 10.4 to 54.6 times faster than other image-based state-of-the-art methods like GANomaly or ALOCC.
  • Accuracy: On the MVTec-AD dataset, ALGAN achieved a mean AUROC of 0.878, significantly outperforming other image-based GAN methods which typically average between 0.75 and 0.79.

Conclusion

ALGAN provides a highly efficient and accurate solution for anomaly detection by leveraging the latent space to generate diverse pseudo-anomalous training data. While the model shows some sensitivity to geometric variations (such as object rotation), its massive speed advantage and competitive accuracy make it a powerful tool for real-time industrial inspection. Future work will focus on improving robustness to geometric shifts and applying the framework to non-image data types.

Summary updated

Abstract

In many anomaly detection tasks, where anomalous data rarely appear and are difficult to collect, training using only normal data is important. Although it is possible to manually create anomalous data using prior knowledge, they may be subject to user bias. In this paper, we propose an Anomalous Latent variable Generative Adversarial Network (ALGAN) in which the GAN generator produces pseudo-anomalous data as well as fake-normal data, whereas the discriminator is trained to distinguish between normal and pseudo-anomalous data. This differs from the standard GAN discriminator, which specializes in classifying two similar classes. The training dataset contains only normal data; the latent variables are introduced in anomalous states and are input into the generator to produce diverse pseudo-anomalous data. We compared the performance of ALGAN with other existing methods on the MVTec-AD, Magnetic Tile Defects, and COIL-100 datasets. The experimental results showed that ALGAN exhibited an AUROC comparable to those of state-of-the-art methods while achieving a much faster prediction time.
BibTeX
@article{murase2022algan,
  author = {Hironori Murase and Kenji Fukumizu},
  title = {{ALGAN: Anomaly Detection by Generating Pseudo Anomalous Data via Latent Variables}},
  journal = {IEEE Access},
  year = {2022},
  doi = {10.1109/access.2022.3169594},
}
Figure