Source-linked AI summary

GANomaly: Semi-Supervised Anomaly Detection via Adversarial Training

Samet Akcay, Amir Atapour-Abarghouei, Toby P. Breckon

arXiv:1805.06725v3cs.CV

TL;DR

The paper targets anomaly detection when abnormal examples are scarce and unseen anomalies must be identified from normal-only training data. It introduces an adversarial encoder-decoder-encoder model that jointly learns image and latent representations, and reports superiority across benchmark datasets and X-ray security screening.

  • Problem

    Anomaly detection must identify scarce or unseen abnormal samples despite training data being highly biased toward normal examples.

  • Method

    GANomaly uses adversarial training with an encoder-decoder-encoder generator to learn image and latent representations jointly from normal samples.

  • Results

    The proposed method outperforms contemporary GAN-based and traditional autoencoder-based approaches across benchmark datasets of varying complexity and X-ray security screening.

  • Takeaways & Limitations

    The architecture provides a general anomaly detection approach that learns normality and detects non-conforming samples through anomaly scoring.

  • Takeaways & Limitations

    The method assumes a large training dataset containing only normal images and a smaller test dataset containing labeled normal and abnormal images.

Abstract

from arXiv · show

Anomaly detection is a classical problem in computer vision, namely the determination of the normal from the abnormal when datasets are highly biased towards one class (normal) due to the insufficient sample size of the other class (abnormal). While this can be addressed as a supervised learning problem, a significantly more challenging problem is that of detecting the unknown/unseen anomaly case that takes us instead into the space of a one-class, semi-supervised learning paradigm. We introduce such a novel anomaly detection model, by using a conditional generative adversarial network that jointly learns the generation of high-dimensional image space and the inference of latent space. Employing encoder-decoder-encoder sub-networks in the generator network enables the model to map the input image to a lower dimension vector, which is then used to reconstruct the generated output image. The use of the additional encoder network maps this generated image to its latent representation. Minimizing the distance between these images and the latent vectors during training aids in learning the data distribution for the normal samples. As a result, a larger distance metric from this learned data distribution at inference time is indicative of an outlier from that distribution - an anomaly. Experimentation over several benchmark datasets, from varying domains, shows the model efficacy and superiority over previous state-of-the-art approaches.

1 Introduction

The paper addresses anomaly detection when abnormal examples are scarce or evolving, using an adversarial architecture trained on normal samples to identify outliers.

  • Motivation: Anomaly detection trains on normal samples and identifies unusual cases that differ from the learned normal distribution.X-ray screening is presented as an application where threatening anomalous items are uncommon and difficult to collect.
  • Problem formulation: A model learns the normal distribution pX and outputs anomaly score A(x), with larger scores indicating possible abnormalities, including unseen anomalies.The score is minimized during training, so non-conforming test samples receive larger values.
  • Related work: GAN-based anomaly detection builds on generators that model high-dimensional data and discriminators that distinguish modeled from original samples.Prior work includes latent-space remapping and jointly learned image-to-latent mappings, with computational complexity and benchmark-scope limitations reported for earlier methods.
  • Contribution: The proposed architecture uses adversarial training with an encoder-decoder-encoder pipeline to capture distributions in image and latent spaces jointly.The approach is trained using only normal, non-anomalous examples and avoids two-stage training.
  • Contribution: The paper claims statistically and computationally better performance than contemporary GAN-based and traditional autoencoder-based approaches.The contributions also emphasize an effective algorithm whose results can be reproduced through publicly available code.

2 Related Work

Prior anomaly detection research spans many domains and increasingly uses reconstruction and adversarial methods, while earlier latent-space approaches face computational or generalization constraints.

  • Scope: Anomaly detection has been studied across biomedical, financial, security, and video domains, with reviews taxonomizing the literature.The related-work review narrows its focus primarily to reconstruction-based anomaly techniques.
  • Reconstruction methods: Reconstruction-based methods have largely targeted video sequences using autoencoders, recurrent networks, local features, and adversarial autoencoders.These approaches are trained on normal samples or combine multiple feature-extraction stages for anomaly detection.
  • Adversarial methods: Adversarial approaches include conditional GANs that generate optical flow and frames for abnormality detection in crowded scenes.Their generalizability is problematic when datasets lack temporal features.
  • Latent-space methods: Schlegl et al. remap images into a GAN latent space, but this requires enormous computational complexity, while BiGAN jointly maps image and latent spaces on MNIST.The cited follow-up reports statistically and computationally superior results on that benchmark.
  • Proposed direction: The paper introduces a conditional adversarial network whose encoder-decoder-encoder generator jointly learns image and latent representations.It positions this design as achieving state-of-the-art statistical and computational performance.

3 Our Approach: GANomaly

The GANomaly approach uses GAN components to model normal image data, with an autoencoder structure that reconstructs inputs and regulates the latent space.

  • Proposed approach: The proposed approach combines GAN and autoencoder ideas to learn normal image representations through adversarial training.Its pipeline is introduced as the basis for anomaly detection in the paper.
  • Generative Adversarial Networks (GAN): GANs use competing generator and discriminator networks: the generator produces images while the discriminator classifies them as real or fake.The generator models high-dimensional data from a latent space to capture the real-data distribution.
  • Generative Adversarial Networks (GAN): GAN training has attracted substantial attention, and methods such as DCGAN address instability using fully convolutional networks and batch normalization.The cited passage notes ongoing empirical efforts to improve GAN training stability.
  • Autoencoders: Autoencoders consist of an encoder and decoder that map inputs to latent space and reconstruct them in the original data space.Adversarial training can improve reconstruction and provide control over the latent space.

Adversarial Auto-Encoders (AAE)

The method frames anomaly detection as learning a normal-only data manifold and flagging test images with sufficiently high anomaly scores.

  • Problem Definition.: The training dataset contains only M normal images, while the smaller test dataset contains N labeled normal and abnormal images, with M ≫ N.This formalizes the highly class-biased setting used by the method.
  • Problem Definition.: The model learns the training manifold and normal distribution while minimizing anomaly scores for normal data.For a test image ˆx, the threshold rule A(ˆx) > φ indicates an anomaly.

Ganomaly Pipeline.

GANomaly uses three sub-networks: a generator that reconstructs images, an encoder that re-encodes reconstructions, and a discriminator that distinguishes real from generated images.

  • Ganomaly Pipeline.: Together, the networks define the multi-network architecture used for the model's learning objective.The architecture discussion leads directly into objective formulation.
  • Ganomaly Pipeline.: The generator encodes an input image into bottleneck vector z and decodes z to reconstruct image x̂.The encoder downsamples the image, while the decoder upsamples the bottleneck representation.
  • Ganomaly Pipeline.: A second encoder maps reconstructed image x̂ to feature representation ẑ with the same dimension as z.This encoder explicitly learns to minimize the distance between the input and reconstructed latent representations.
  • Ganomaly Pipeline.: The discriminator classifies input x and generated output x̂ as real or fake, respectively.It uses the standard DCGAN discriminator architecture.

3.2 Model Training

Model training combines adversarial, contextual, and encoder objectives so generated images are realistic, contextually faithful, and aligned in latent space.

  • 3.2 Model Training: Abnormal inputs are expected to produce reconstructions that miss abnormal features, creating dissimilarity between their original and reconstructed latent vectors.The networks are trained only on normal samples, so their parametrization is not suited to generating abnormal samples.
  • 3.2 Model Training: Feature matching updates the generator using intermediate discriminator representations rather than only real/fake outputs.The feature-matching loss computes an L2 distance between representations of original and generated images.
  • 3.2 Model Training: Adversarial loss can fool the discriminator, but alone it does not optimize the generator to learn contextual information from the input.A distance penalty between input and generated images addresses this limitation.
  • 3.2 Model Training: The contextual loss penalizes the L1 distance between original image x and generated image x̂.The cited discussion associates L1 with less blurry results than L2.
  • 3.2 Model Training: The encoder loss minimizes the distance between input bottleneck features z and encoded features ẑ of the generated image.This adds latent-space consistency to the adversarial and contextual objectives.

Encoder Loss.

The encoder loss supports latent representation matching for normal samples and is used to expose feature-space mismatch for anomalous inputs.

  • Encoder Loss.: The generator learns to encode generated-image features for normal samples through the combined training objective.For anomalous inputs, the networks fail to minimize feature-space distance because they are optimized only on normal samples.
  • Encoder Loss.: The overall generator objective combines adversarial, contextual, and encoder losses with weighting parameters.The weights adjust each loss's impact on the total objective.
  • Encoder Loss.: Figure 3 compares AnoGAN, Efficient-GAN-Anomaly, and GANomaly as three model architectures.The figure labels the proposed approach as GANomaly.

3.3 Model Testing

At test time, GANomaly scores samples using encoder-loss distance and scales the resulting test-set scores to the range [0, 1].

  • 3.3 Model Testing: The model uses the encoder loss to score the abnormality of each test sample.The anomaly score is defined from the distance between the sample's encoded and reconstructed latent representations.
  • 3.3 Model Testing: Individual test-sample scores are collected into a set S for the test set.The set contains one anomaly score for each test sample.
  • 3.3 Model Testing: The final evaluation uses an anomaly score vector S′ produced from the test set.This vector results after applying the stated score-processing procedure.

4 Experimental Setup

The framework is evaluated on benchmark and operational X-ray datasets using normal-only training, with anomaly detection assessed against held-out abnormal classes and comparative GAN and autoencoder baselines.

  • Dataset Protocol: MNIST and CIFAR designate one class as abnormal and train on the remaining classes as normal data.MNIST forms ten anomaly settings by selecting each digit in turn; CIFAR similarly treats one class as abnormal.
  • Implementation and Evaluation: The model is compared with DCGAN-based adversarial approaches and a variational autoencoder under a consistent standard DCGAN training setup.The comparisons include AnoGAN, EGBAD, and VAE, implemented in PyTorch and optimized with Adam.

5 Results

Across image benchmarks and X-ray datasets, GANomaly generally achieves the strongest anomaly-detection performance and runtime, while latent-space and loss-weight choices affect results.

  • Benchmark Results: GANomaly achieves the best AUC for every anomalous class tested on CIFAR10 and higher AUC than EGBAD, AnoGAN, and VAE on MNIST.MNIST results use three random seeds; CIFAR performance is lower when normal and abnormal categories are visually similar.
  • X-ray Results: 0.666 and 0.882 are the overall AUCs reported for GANomaly on UBA and FFOB, respectively, exceeding other approaches overall.The knife class is an exception, with comparable performance attributed to shape simplicity and overfitting-related false positives.
  • Sensitivity Analysis: The highest MNIST AUC occurs with latent-vector size z = 100 and loss weights w_bce = 1, w_rec = 50, and w_enc = 1.The same loss-weight tuning pattern is observed empirically across the remaining datasets.
  • Representation Analysis: Normal and abnormal samples show clear separation in both anomaly-score histograms and discriminator features visualized with t-SNE.
  • Runtime: GANomaly has the highest runtime performance among the compared GAN-based approaches, whereas AnoGAN is computationally expensive because it optimizes a latent vector for each example.UBA and FFOB runtimes are comparable to MNIST despite larger image and network sizes.
  • Qualitative Analysis: On MNIST, the model can generate unseen anomalous digit-2 samples, but latent-vector distance still provides anomaly-detection information.For the other illustrated datasets, the model is unable to produce abnormal objects.

6 Conclusion

The paper concludes that its adversarial encoder-decoder-encoder model performs strongly across datasets of varying complexity and an operational X-ray security-screening setting.

  • Conclusion: The proposed encoder-decoder-encoder adversarial model outperforms contemporary GAN-based and traditional autoencoder-based anomaly-detection approaches across varied benchmarks and X-ray screening data.The authors describe the approach as generalizable to anomaly-detection tasks and identify GAN optimization as future work.
Loading 1805.06725v3…