InFlow: Robust outlier detection utilizing Normalizing Flows

Nishant Kumar, Pia Hanfeld, Michael Hecht, Michael Bussmann, Stefan Gumhold, Nico HoffmannarXiv 2021

Abstract

Normalizing flows are prominent deep generative models that provide tractable probability distributions and efficient density estimation. However, they are well known to fail while detecting Out-of-Distribution (OOD) inputs as they directly encode the local features of the input representations in their latent space. In this paper, we solve this overconfidence issue of normalizing flows by demonstrating that flows, if extended by an attention mechanism, can reliably detect outliers including adversarial attacks. Our approach does not require outlier data for training and we showcase the efficiency of our method for OOD detection by reporting state-of-the-art performance in diverse experimental settings. Code available at https://github.com/ComputationalRadiationPhysics/InFlow .

Introduction: The Overconfidence Problem

In safety-critical applications like autonomous driving or medical diagnosis, a machine learning model must know when it is looking at something it hasn't seen before—this is Out-of-Distribution (OOD) detection. Normalizing Flows (NFs) are a class of deep generative models that are theoretically perfect for this task because they provide exact probability density estimation. In theory, if a sample is OOD, the model should assign it a low likelihood.

However, in practice, NFs often suffer from an "overconfidence issue": they frequently assign higher likelihoods to OOD data than to the data they were trained on. This happens because standard NFs tend to capture low-level pixel correlations rather than high-level semantic meaning. For example, a model trained on complex CelebA images might assign a higher likelihood to simpler datasets like FashionMNIST.

Trained RealNVP showing overconfidence

Methods: The InFlow Architecture

We introduce InFlow, which modifies the standard coupling block architecture of Normalizing Flows by adding an attention mechanism, $c(x)$.

  1. The Attention Gate: The function $c(x)$ acts as a gate. If a sample $x$ is determined to be in-distribution, $c(x) \approx 1$, and the model performs its standard complex transformation. If the sample is OOD, $c(x) \approx 0$.
  2. The Identity Trick: When $c(x) = 0$, the mathematical formulation of InFlow causes the transformation to collapse into an identity mapping ($f(x) = x$). In this state, the model simply returns the likelihood of the sample under the Gaussian prior. Because the learned likelihood for in-distribution data is much higher than this prior, OOD samples are naturally "pushed down" to a lower likelihood score.
  3. MMD-based Attention: To decide if a sample is OOD, InFlow uses Maximum Mean Discrepancy (MMD), a statistical test that compares the distribution of a new batch of samples against the training data. To make this efficient, they use a small convolutional encoder to reduce the images to a lower-dimensional feature space before running the MMD test.
  4. Robust Thresholding: The authors derive a data-independent, likelihood-based threshold ($L_{th}$) based on a significance p-value ($\alpha$). This allows users to tune the sensitivity of the outlier detector.

Experimental Evaluation

The researchers evaluated InFlow across a wide array of benchmarks, including standard vision datasets (CelebA, CIFAR-10, MNIST, SVHN), synthetic noise, and adversarial attacks designed to fool Reinforcement Learning agents.

InFlow model showing clear OOD separation

As shown in the figure above, InFlow achieves a clear separation between the training distribution (CelebA) and various OOD datasets. In experiments, InFlow achieved an AUCROC of 1.0 (perfect detection) against almost all OOD datasets, including MNIST, SVHN, and Noise. Furthermore, InFlow proved highly effective at detecting "invisible" adversarial perturbations in Atari RL experiments, with AUCROC scores often exceeding 0.9.

Conclusion

InFlow effectively mitigates the overconfidence issue in Normalizing Flows by leveraging an attention mechanism and statistical testing. By defaulting to the prior distribution for unknown data, it provides a robust safety net for OOD detection without requiring outlier data during training. Future work will explore the hybrid relationship between InFlow's attention mechanism and generative modeling to further enhance robustness.

Summary updated

BibTeX
@misc{kumar2021inflow,
  author = {Nishant Kumar and Pia Hanfeld and Michael Hecht and Michael Bussmann and Stefan Gumhold and Nico Hoffmann},
  title = {{InFlow: Robust outlier detection utilizing Normalizing Flows}},
  year = {2021},
  eprint = {2106.12894},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2106.12894},
}
Figure