A Simple Unified Framework for Detecting Out-of-Distribution Samples and Adversarial Attacks

Kimin Lee, Kibok Lee, Honglak Lee, Jinwoo Shin

Overview

This paper presents a simple yet powerful framework for detecting both out-of-distribution (OOD) samples and adversarial attacks using a Mahalanobis distance-based confidence score. By modeling the internal features of a pre-trained neural network as class-conditional Gaussian distributions, the authors create a "plug-and-play" detector that significantly outperforms previous state-of-the-art methods without requiring model retraining.

The Challenge: Overconfident Neural Networks

Deep Neural Networks (DNNs) are notoriously "overconfident." Even when presented with an image that looks nothing like its training data (OOD) or an image specifically crafted to fool it (adversarial), a standard softmax classifier will often assign a high probability to a wrong class.

The core challenge is measuring predictive uncertainty. While previous research addressed OOD detection and adversarial detection as separate problems, this paper seeks a unified, "generative" approach. The goal is to find a way to tell if a test sample is "far away" from the training distribution in a way that is robust, easy to implement on existing models, and effective against multiple types of anomalies.

A Generative Approach: The Mahalanobis Distance

The authors propose a three-step approach based on Gaussian Discriminant Analysis (GDA):

  1. Mahalanobis Distance Score: They assume that the features extracted from the penultimate layer of a pre-trained DNN follow a multivariate Gaussian distribution for each class, sharing a common covariance matrix. For any new test sample, they calculate the Mahalanobis distance to the nearest class mean. This distance serves as the base confidence score.
  2. Input Pre-processing: To better separate in-distribution and OOD samples, they add a small amount of controlled noise to the input. This noise is designed to increase the Mahalanobis score of "normal" samples more than "abnormal" ones, making them easier to distinguish.
  3. Feature Ensemble: Recognizing that different layers of a DNN capture different information, they extract Mahalanobis scores from multiple layers (not just the last one). They then use a simple logistic regression model to combine these scores into a final, unified detection value.

Crucially, this method is training-free for the underlying classifier; it only requires calculating empirical means and covariances from the training set.

Key Insights

  • The Softmax-GDA Connection: The authors highlight a theoretical link: a standard softmax classifier is mathematically equivalent to a generative Gaussian classifier with a tied covariance. This justifies why modeling features as Gaussians works so well on models already trained with softmax.
  • Feature Space > Probability Space: Abnormal samples are often better separated in the internal "representation space" of the network than in the final "output probability space." Softmax tends to squash useful distance information.
  • Layer-wise Synergy: Low-level features (from earlier layers) are surprisingly effective at catching certain types of anomalies that high-level features might miss. Combining them via an ensemble provides the most robust defense.
AUROC performance across different basic blocks (layers) of the network on the SVHN dataset.
  • Robustness to "Harsh" Data: Unlike methods that rely on perfectly calibrated probabilities, the Mahalanobis approach remains effective even when the training set is small or contains noisy labels.

Performance and Results

The framework was evaluated across a wide range of standard computer vision benchmarks, including CIFAR-10, CIFAR-100, SVHN, TinyImageNet, and LSUN, as well as against various adversarial attacks (FGSM, BIM, DeepFool, CW).

Visualization of feature space, classification accuracy, and ROC curve performance comparing Mahalanobis to baselines.
  • OOD Detection: On a ResNet model, the proposed method improved the True Negative Rate (TNR) at a 95% True Positive Rate from 45.6% (using the previous state-of-the-art, ODIN) to 90.9% when detecting LSUN samples against a CIFAR-100 background.
  • Adversarial Detection: It outperformed the specialized Local Intrinsic Dimensionality (LID) method. For the difficult CW attack on ResNet, it improved the detection rate (TNR) from 82.9% to 95.8%.
  • Class-Incremental Learning: The method allows a model to "learn" new classes on the fly by simply updating means and covariances. It significantly outperformed Euclidean and softmax-based baselines, showing it can mitigate "catastrophic forgetting" in simple classification tasks.

Limitations and Future Work

  • Hyperparameter Tuning: While the method is robust, the "Feature Ensemble" step requires a small validation set of OOD or adversarial samples to train the logistic regression weights. The authors suggest using simple FGSM-generated samples if real OOD data isn't available, but this is still a dependency.
  • Tied Covariance Assumption: The assumption that all classes share the same covariance matrix simplifies the math and prevents overfitting, but it might be too restrictive for extremely diverse datasets with hundreds of thousands of classes.
  • Computational Cost: Calculating distances and gradients across multiple layers adds some latency during inference, which might be a concern for real-time edge applications.

Summary updated

BibTeX
@inproceedings{lee2018simple,
  author = {Kimin Lee and Kibok Lee and Honglak Lee and Jinwoo Shin},
  title = {{A Simple Unified Framework for Detecting Out-of-Distribution Samples and Adversarial Attacks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2018},
  url = {https://openreview.net/forum?id=S1ZqgdW_-B},
}
Figure