Exploring the Limits of Out-of-Distribution Detection

Stanislav Fort, Jie Ren, Balaji Lakshminarayanan

TL;DR

This paper demonstrates that large-scale pre-trained transformers (like ViT, BERT, and CLIP) are surprisingly effective at "near-OOD" detection—distinguishing between very similar data distributions. By leveraging high-quality representations from pre-training and novel techniques like "few-shot outlier exposure," the authors push the state-of-the-art on challenging benchmarks from ~85% to over 99% AUROC.

Introduction: The OOD Problem

Deep learning models are notoriously overconfident. When shown an image of something they’ve never seen before (Out-of-Distribution, or OOD), they often assign it a high-probability label from their training set. This is a major safety hurdle for real-world deployment in areas like healthcare or autonomous driving.

The community generally splits OOD detection into two flavors:

  1. Far-OOD: Easy cases where the outlier is semantically distinct (e.g., a model trained on animal photos seeing a picture of a house number).
  2. Near-OOD: Hard cases where outliers are semantically similar (e.g., a model trained on CIFAR-100 seeing an image from a class in CIFAR-10 it wasn't trained on).

While Far-OOD is largely considered "solved" with near-perfect scores, Near-OOD has remained a stubborn challenge. This paper investigates whether the massive scale of modern transformer pre-training can finally close that gap.

Methodology

The authors evaluate three main strategies for OOD detection using transformers:

  • Standard Fine-tuning: They fine-tune pre-trained models (Vision Transformers for images, BERT for genomics) on in-distribution data and use standard scoring methods like Maximum Softmax Probability (MSP) and Mahalanobis distance in the embedding space to identify outliers.
  • Few-shot Outlier Exposure: They explore a scenario where a developer might have access to just a handful (1–10) of examples from an outlier class. They train a simple linear classifier or MLP on top of the transformer's frozen embeddings to distinguish between the "in-distribution" and these "known unknowns."
  • Zero-shot Outlier Exposure (CLIP): For multi-modal models like CLIP, they propose a clever trick: using the names of potential outlier classes as text labels. By comparing the image embedding to the text embeddings of both in-distribution and outlier class names, they can detect OOD inputs without ever seeing a single outlier image during training.

Datasets

The study spans two very different modalities:

  • Computer Vision: They use CIFAR-10 and CIFAR-100 as mutual OOD tasks (training on one, testing on the other). They also use SVHN (digits) and Textures for Far-OOD benchmarks.
  • Genomics: They use a benchmark consisting of 10 bacterial classes for in-distribution training and 60 bacterial classes (discovered in later years) as OOD test cases. This is a particularly difficult task because the "near-OOD" sequences are biologically very similar to the training data.

Key Insights and Ideas

PCA projections comparing ResNet and ViT embeddings for OOD detection
  • Pre-training is the "Secret Sauce": The biggest jump in performance comes from the quality of the embeddings. Large-scale pre-training (e.g., on ImageNet-21k) creates a feature space where semantically similar classes are already well-clustered and separated, making the OOD task much easier.
  • Transformers > ResNets: Even when compared to high-performing ResNet variants (like BiT), Vision Transformers (ViT) consistently provide better OOD detection. As visualized in the PCA projections above, ViT embeddings naturally separate in-distribution and OOD classes much more cleanly than ResNets. The authors suggest transformers may be less prone to "shortcut learning," making their representations more robust.
  • The Power of a Few Examples: "Few-shot outlier exposure" is incredibly potent. Adding just one image per OOD class can jump the AUROC from 96% to 98.7%. With 10 images, it hits 99.46%, effectively "solving" the near-OOD problem.
  • Language as a Prior: The CLIP results are perhaps the most surprising. By simply telling the model the names of classes it might see (e.g., "automobile" for a model trained on "trucks"), the model can leverage its internal world knowledge to flag those inputs as OOD with high accuracy.

Key Results

AUROC improvements on CIFAR-100 and CIFAR-10 OOD tasks
  • CIFAR-100 vs CIFAR-10: As shown in the charts above, the authors improved the state-of-the-art AUROC from 85.6% to over 96% using a standard ViT, even surpassing human baseline performance. With few-shot exposure (10 images/class), this reached 99.46%.
  • Genomics: Using BERT and unsupervised pre-training, they improved the AUROC from 66% to 77%. With few-shot exposure, this rose to 86%.
  • Zero-shot CLIP: On the CIFAR-100 vs CIFAR-10 task, CLIP achieved 94.68% AUROC using only class names—outperforming many previous methods that required full training sets.

Limitations and Future Work

  • Data Dependency: These methods rely heavily on massive pre-training datasets (ImageNet-21k, 400M image-text pairs for CLIP). It is unclear how well these findings translate to niche domains where such massive datasets don't exist.
  • Known Unknowns: The "outlier exposure" methods assume you can anticipate at least some of the outlier classes. While the authors show this generalizes well to unseen outliers, the choice of "exposure" classes remains a design variable.
  • Genomics Gap: While the genomics results are a significant step forward, they still lag behind vision performance, suggesting that unsupervised pre-training for biological sequences still has room for improvement.

Summary updated

Abstract

Near out-of-distribution detection (OOD) is a major challenge for deep neural networks. We demonstrate that large-scale pre-trained transformers can significantly improve the state-of-the-art (SOTA) on a range of near OOD tasks across different data modalities. For instance, on CIFAR-100 vs CIFAR-10 OOD detection, we improve the AUROC from 85% (current SOTA) to more than 96% using Vision Transformers pre-trained on ImageNet21k. On a challenging genomics OOD detection benchmark, we improve the AUROC from 66% to 77% using transformer and unsupervised pre-training. To further improve performance, we explore the few-shot outlier exposure setting where a few examples from outlier classes may be available; we show that pre-trained transformers are particularly well-suited for outlier exposure, and that the AUROC of OOD detection on CIFAR-100 vs CIFAR-10 can be improved to 98.7% with just 1 image per OOD class, and 99.46% with 10 images per OOD class. For multi-modal image-text pre-trained transformers such as CLIP, we explore a new way of using just the names of outlier classes as a sole source of information without any accompanying images, and show that this outperforms previous SOTA on standard OOD benchmark tasks.
BibTeX
@inproceedings{fort2021exploring,
  author = {Stanislav Fort and Jie Ren and Balaji Lakshminarayanan},
  title = {{Exploring the Limits of Out-of-Distribution Detection}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=j5NrN8ffXC},
}
Figure