Out-of-distribution detection

Also known as: OOD detection

On this page 7

Out-of-distribution detection (OOD detection) is the task of deciding whether an input to a trained machine learning model comes from the same distribution as its training data or from a different, unfamiliar one. Within anomaly detection, it focuses on protecting a deployed predictive model: instead of returning a confident but meaningless answer for an unfamiliar input, the system flags, rejects or escalates it.

OOD detection matters because modern classifiers, especially deep neural networks, are often overconfident on inputs they have never seen. A skin lesion classifier shown a photograph of a ruler, or a self-driving perception model shown an unusual vehicle, may still output a high softmax probability. OOD detection adds a separate score and threshold that measures how unfamiliar the input is.

What counts as out of distribution

An input is out of distribution when it is unlikely under the training distribution the model learned from. In practice, researchers distinguish two kinds of shift, and OOD detection traditionally targets the first one.

Shift typeWhat changesExampleTypical goal
Semantic shiftNew classes not in the label setA bird in a cat-and-dog classifierDetect and reject
Covariate shiftInput style changes, classes stayNight images for a daytime modelDetect or adapt
Near OODSimilar but unseen classesA new dog breed among known breedsHardest to detect
Far OODEntirely different dataText noise sent to an image modelUsually easy to detect
Types of distribution shift relevant to OOD detection

The term overlaps with novelty detection, open-set recognition and outlier detection. The usual distinction is one of purpose: classic outlier detection cleans or analyzes a dataset, whereas OOD detection guards a classifier or regressor at inference time, so its score is often computed from the model itself.

How OOD detection methods score inputs

Every OOD detector produces an OOD score for each input and compares it with a threshold chosen on in-distribution validation data. Methods differ in where the score comes from: the model’s outputs, its internal features, a separate density model or extra training with outlier examples.

FamilyScore sourceRepresentative methodsRetraining needed
Output-basedLogits or softmaxMaximum softmax probability, energy scoreNo
Feature-basedPenultimate-layer embeddingsMahalanobis distance, k-nearest neighborsNo, needs feature statistics
Activation shapingModified internal activationsReAct, ASHNo
Density or generativeLikelihood under a generative modelNormalizing flows, likelihood ratiosSeparate model
Outlier exposureTraining with auxiliary outliersOutlier exposure lossYes
Main families of OOD detection methods

The simplest baseline, the maximum softmax probability, treats low top-class confidence as a sign of unfamiliar input. The energy score uses the log-sum-exp of logits and is usually more reliable. Feature-based approaches such as Mahalanobis distance and k-nearest neighbor distance in embedding space are strong for near OOD, because they measure how far an input lies from known class clusters.

Generative models seem a natural fit, but they carry a well-known pitfall: likelihoods can be higher for OOD data than for training data, as shown when models trained on one image dataset assigned higher likelihood to simpler images from another. Likelihood-ratio and typicality corrections reduce this problem.

How OOD detectors are evaluated

OOD detection is evaluated as a binary decision problem between in-distribution and OOD test sets. Results depend heavily on which OOD datasets are chosen, so reported numbers are comparable only within the same benchmark protocol, such as the OpenOOD suite.

MetricWhat it measuresBetter value
AUROCRanking quality across all thresholdsHigher, 1.0 is perfect
FPR at 95 percent TPROOD inputs accepted when 95 percent of normal inputs passLower
AUPRPrecision and recall balance under imbalanceHigher
In-distribution accuracyWhether detection harms the main taskUnchanged or higher
Common evaluation metrics for OOD detection

The FPR at 95 percent TPR is often the most informative metric for deployment, because it states directly how many unfamiliar inputs slip through at a fixed, practical acceptance rate for normal data.

Deploying OOD detection in production

In production, OOD detection is part of a reject option: inputs above the threshold go to a human reviewer, a fallback rule or a safer model. The threshold is a business trade-off between missed OOD inputs and unnecessary escalations, and it should be set on validation data that reflects real traffic.

  • Start with post-hoc scores such as energy or k-nearest neighbor distance, which need no retraining.
  • Validate on realistic near-OOD data, because far-OOD benchmarks overstate performance.
  • Monitor score drift over time, since a rising share of flagged inputs signals covariate shift.
  • Combine with calibration, because a well-calibrated model makes output-based scores more meaningful.

Limitations and common misconceptions

No OOD detector works universally, because the space of possible unfamiliar inputs is unbounded. A method tuned on one set of outliers can fail on another, and adversarial inputs can be crafted to evade the score.

MistakeConsequenceBetter practice
Trusting softmax confidence aloneOverconfident errors pass unnoticedUse energy or feature-based scores
Testing only on far OODInflated results, poor field performanceInclude near-OOD test sets
Tuning on the test outliersOptimistic, non-transferable thresholdsHold out OOD data used for tuning
Ignoring covariate shiftSilent accuracy loss on new conditionsTrack drift alongside OOD scores
Frequent mistakes in OOD detection projects

A frequent misconception is that a high-accuracy model is automatically safe on unfamiliar data. Accuracy on the test set says nothing about behavior outside the training distribution, which is precisely the gap OOD detection is meant to cover.

A plain-language summary

An AI model learns from examples. When it sees something completely new, it may still give a confident answer that is wrong. It does not know that it does not know.

OOD detection is a warning light for unfamiliar inputs. It checks whether a new input looks like what the model studied. If not, the system can say “this is outside my experience” and pass the case to a person.

An example from practice

A hospital uses an image classifier to sort chest X-rays into normal and several disease categories. The model was trained on adult scans from two scanner brands. Radiologists worry about scans from a new pediatric unit and about images with artifacts from medical devices.

The data science team adds a k-nearest neighbor distance score on the model’s embeddings. They set the threshold so that 95 percent of typical adult scans pass without review. In a pilot, the detector flags most pediatric scans and heavily distorted images, while very few normal adult scans are escalated.

Flagged images skip the automated label and go straight to a radiologist. The result is fewer confident misclassifications on unfamiliar scans, at the cost of a modest extra review workload that the department considers acceptable.