Exploring the Limits of Out-of-Distribution Detection

Stanislav Fort, Jie Ren, Balaji Lakshminarayanan

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 ImageNet-21k. On a challenging genomics OOD detection benchmark, we improve the AUROC from 66% to 77% using transformers 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 vision OOD benchmark tasks.

Introduction

Deep neural networks often fail silently when they encounter data they weren't trained on, assigning high-confidence predictions to inputs that don't belong to any known category. This is a major hurdle for deploying AI in safety-critical fields like healthcare or autonomous driving.

This research specifically targets near-OOD detection. While "far-OOD" tasks (e.g., a model trained on digits trying to classify a dog) are relatively easy and often achieve ~99% AUROC, "near-OOD" tasks (e.g., a model trained on CIFAR-100 trying to detect a CIFAR-10 image) are much harder because the classes are semantically similar. Before this work, the state-of-the-art (SOTA) for near-OOD on CIFAR-100 vs. CIFAR-10 was stuck around 85% AUROC.

Methodology

The researchers explore three main avenues using transformer architectures:

  1. Fine-tuning Pre-trained Transformers: They utilize Vision Transformers (ViT) pre-trained on ImageNet-21k and BERT models for genomics, fine-tuning them on in-distribution data. They then apply standard OOD scores like Maximum Softmax Probability (MSP) and Mahalanobis distance in the embedding space.
  2. Few-shot Outlier Exposure: They investigate a scenario where a developer might have access to just a handful (1–10) of examples from outlier classes. They use these to train a simple linear classifier or MLP on top of the transformer's embeddings to better distinguish "in" from "out."
  3. Zero-shot OOD with Multi-modal Models: Using CLIP, they propose a novel method that requires no outlier images. Instead, they provide the names of potential outlier classes as candidate text labels, leveraging the model's joint image-text understanding to flag inputs that align better with these "outlier" names than with the "inlier" names.

Visualizing Representation Quality

A key insight of this work is that large-scale pre-training makes models less vulnerable to "shortcut learning." Instead of relying on simple textures, transformers learn robust semantic representations that are naturally better at separating similar classes.

Comparison of feature representations between ResNet and ViT models. Fine-tuned ViT shows superior class separation.

As shown in the PCA visualizations above, standard ResNet architectures exhibit significant overlap between in-distribution and OOD classes. In contrast, pre-trained transformers—especially after fine-tuning—create highly clustered representations that naturally facilitate the separation of similar classes. While pre-training provides good features, fine-tuning on the in-distribution task "clusters" the embeddings by class, making the Mahalanobis distance exceptionally effective for OOD detection.

Key Results

The performance gains across vision and genomics benchmarks are transformative. On the CIFAR-100 vs. CIFAR-10 task, ViT improves AUROC from the previous SOTA of 85% to over 96%.

AUROC performance on near-OOD tasks. ViT models significantly outperform previous hybrid SOTA and approach human-level performance.
  • Genomics: Improved AUROC from 66% to 77% using BERT. Few-shot exposure further boosted this to 86%.
  • Zero-shot CLIP: Achieved 94.8% AUROC on CIFAR-100 vs. CIFAR-10 using only class names—outperforming previous methods that actually trained on the images.
  • Human Parity: The authors benchmarked human performance on the CIFAR near-OOD task and found it to be around 95.9% AUROC, suggesting their best models are now performing at or above human level on these specific tasks.

Discussion and Limitations

Qualitative analysis reveals that many remaining "errors" are due to genuine ambiguity or mislabeling in the datasets (e.g., a "truck" in one dataset being a "tractor" in another). The models are reaching a point where they are limited by the quality of the benchmarks themselves.

Despite these successes, the gains rely on massive pre-training, which is computationally expensive. Furthermore, the zero-shot CLIP method requires knowing the names of potential outliers in advance, which isn't always possible in "open-world" scenarios. Future work should focus on better unsupervised pre-training strategies to reduce reliance on labeled data and extending these findings to other modalities like audio or medical imaging.

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 ImageNet-21k. On a challenging genomics OOD detection benchmark, we improve the AUROC from 66% to 77% using transformers 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 vision 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