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 type | What changes | Example | Typical goal |
|---|---|---|---|
| Semantic shift | New classes not in the label set | A bird in a cat-and-dog classifier | Detect and reject |
| Covariate shift | Input style changes, classes stay | Night images for a daytime model | Detect or adapt |
| Near OOD | Similar but unseen classes | A new dog breed among known breeds | Hardest to detect |
| Far OOD | Entirely different data | Text noise sent to an image model | Usually easy to detect |
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.
| Family | Score source | Representative methods | Retraining needed |
|---|---|---|---|
| Output-based | Logits or softmax | Maximum softmax probability, energy score | No |
| Feature-based | Penultimate-layer embeddings | Mahalanobis distance, k-nearest neighbors | No, needs feature statistics |
| Activation shaping | Modified internal activations | ReAct, ASH | No |
| Density or generative | Likelihood under a generative model | Normalizing flows, likelihood ratios | Separate model |
| Outlier exposure | Training with auxiliary outliers | Outlier exposure loss | Yes |
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.
| Metric | What it measures | Better value |
|---|---|---|
| AUROC | Ranking quality across all thresholds | Higher, 1.0 is perfect |
| FPR at 95 percent TPR | OOD inputs accepted when 95 percent of normal inputs pass | Lower |
| AUPR | Precision and recall balance under imbalance | Higher |
| In-distribution accuracy | Whether detection harms the main task | Unchanged or higher |
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.
| Mistake | Consequence | Better practice |
|---|---|---|
| Trusting softmax confidence alone | Overconfident errors pass unnoticed | Use energy or feature-based scores |
| Testing only on far OOD | Inflated results, poor field performance | Include near-OOD test sets |
| Tuning on the test outliers | Optimistic, non-transferable thresholds | Hold out OOD data used for tuning |
| Ignoring covariate shift | Silent accuracy loss on new conditions | Track drift alongside OOD scores |
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.