- Introduced by
- Hendrycks & Gimpel
- Year
- 2017
- Type
- Reliability and safety method for neural networks
- Family
- Trustworthy ML
What does it do?
Out-of-Distribution (OOD) detection is a set of techniques that identify when a deployed machine learning model receives inputs that differ significantly from its training data distribution.
Hendrycks and Gimpel (2017) addressed this problem for neural classifiers and proposed a simple softmax-based baseline. These methods let a model flag unfamiliar inputs instead of silently returning unreliable predictions, which matters in high-stakes deployments. Related terms such as novelty detection and open-set recognition overlap with it but are usually framed under different protocols.
The intuition behind the method
Imagine a doctor trained only on X-ray images of lungs who is suddenly handed an MRI scan of a knee. The doctor may still output a diagnosis — but the input is nothing like what was learned. OOD detection acts as a gatekeeper: before a model answers, it checks whether the question looks like something it has genuinely seen before. If not, it raises a flag instead of guessing confidently on unfamiliar ground.
History
Hendrycks and Gimpel (2017) proposed a baseline that uses the maximum softmax probability of a neural classifier to detect misclassified and out-of-distribution examples. Subsequent research has proposed alternative scoring functions for OOD detection in neural networks, and the problem has since become a common topic in trustworthy machine learning research.
When to use it
Choose this baseline when you already have a trained softmax classifier, need a cheap binary flag, and can assemble two data sources: a representative held-out in-distribution validation set to fix the 95% retention target, and labelled OOD samples resembling the expected deployment shift to estimate the false positive rate. It is a reasonable first check in open-world settings such as medical diagnosis, autonomous driving, fraud detection or industrial inspection, where the test distribution may drift from the training data. Do not rely on it when no in-distribution validation data is available. Be cautious when no labelled OOD data is available either, since only the retention target can then be set. It is also a weak choice when OOD inputs are semantically close to the training classes (near-OOD), when in-distribution and OOD inputs share similar feature representations, or when you need graded uncertainty rather than a yes/no decision. For those cases, alternative scoring methods from the later OOD literature, and approaches that provide graded uncertainty, should be evaluated.
Limitations and considerations
- Neural networks can produce high-confidence softmax scores even for clearly OOD inputs due to the nature of the softmax function.
- Threshold calibration requires a representative in-distribution validation set and labelled OOD samples for the false positive criterion, which may be difficult to curate in practice.
- Performance degrades when OOD data is semantically close to training data (near-OOD detection is harder than far-OOD).
- Does not provide fine-grained uncertainty estimates; only a binary in/out decision at a fixed threshold.
- Relies on assumptions: a classifier trained with cross-entropy whose final softmax layer outputs class probabilities, and OOD inputs that tend to receive lower maximum softmax scores than in-distribution inputs. Where these do not hold, the score gives little separation.
- The threshold is tied to the model and data used to set it; retraining or fine-tuning requires re-running threshold calibration with fresh in-distribution and OOD data.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Simple and training-free: the baseline method requires no model retraining, making it easy to bolt onto any existing classifier.
- Reference baseline: it was proposed by Hendrycks and Gimpel as a baseline for detecting misclassified and out-of-distribution examples, so it gives a simple point of comparison for newer OOD scoring methods.
- Interpretable scoring: a single scalar confidence score is easy to communicate and threshold for operational use.
- Broadly applicable: the framework applies to any neural network that outputs a probability distribution over classes.
Applications
- Medical imaging: flagging radiographs or scans from rare pathologies not represented in training data before automated diagnosis.
- Autonomous driving: detecting unusual road conditions, objects, or scenarios that fall outside the training distribution of perception models.
- Financial fraud detection: identifying transaction patterns that deviate from the distribution of known legitimate or fraudulent behavior.
- Natural language processing: detecting out-of-scope user queries in dialogue systems to trigger graceful fallback responses.
- Industrial quality control: flagging defect types or product variants not seen during model training on manufacturing lines.
How it works
How it works
A standard neural classifier is trained on labeled in-distribution data. The final layer applies a softmax transformation to logits z, mapping raw scores to a probability vector f(x) over classes. This trained network is then repurposed as the backbone for OOD scoring without any architectural changes.
Formula
f(x) = \text{softmax}(z), \quad z = W \phi(x) + bThe maximum softmax probability across all classes is used as the confidence score. Hendrycks and Gimpel reported that in-distribution examples tend to yield higher maximum softmax scores than OOD examples, which gives a simple scalar signal for separating the two groups. The signal is heuristic: a high softmax value does not guarantee that an input is close to the training data.
Formula
\hat{p}(x) = \max_{k} f_k(x) = \max_{k} \frac{e^{z_k}}{\sum_{j} e^{z_j}}The threshold δ* is defined by the formula in the mechanics: it is the value that minimises the false positive rate (OOD inputs accepted as in-distribution) subject to a true positive rate (retention of in-distribution samples) of at least 0.95. This formula is the FPR-at-95%-TPR evaluation metric, and computing it requires labelled OOD samples. For deployment, the same logic applies: a held-out in-distribution validation set fixes the 95% retention target, while labelled OOD samples that resemble the expected deployment shift are needed to judge the false positive rate. Without OOD data, only the retention target can be set, and the false positive rate of the deployed threshold remains unknown. The OOD data used for tuning should be stated explicitly. AUROC and FPR at 95% TPR are standard evaluation metrics.
Formula
\delta^* = \arg\min_{\delta} \text{FPR}(\delta) \quad \text{s.t.} \quad \text{TPR}(\delta) \geq 0.95At inference time, a new sample x is passed through the trained network. If its maximum softmax probability falls below the threshold, the sample is flagged as OOD and the model's prediction is withheld or escalated for human review. Samples above the threshold are treated as in-distribution and their class predictions are returned normally.
Formula
\text{OOD}(x) = \mathbf{1}[\hat{p}(x) < \delta^*]Common pitfalls
- Assuming high softmax confidence implies in-distribution membership — this assumption frequently fails for neural networks without additional calibration.
- Evaluating OOD detection only on far-OOD benchmarks (e.g., Gaussian noise) and reporting inflated performance metrics.
- Neglecting to re-calibrate the detection threshold when the model is updated or fine-tuned on new data.
- Conflating OOD detection with adversarial robustness — they are related but distinct problems requiring separate evaluation protocols.
Frequently asked questions
Is OOD detection the same as anomaly detection?
They are closely related but not identical. Anomaly detection is a broad family of methods for finding unusual observations, including unsupervised settings with no labelled data. OOD detection is usually framed around a pre-trained supervised classifier and asks whether that classifier's inputs are reliable at deployment. The two overlap, and where the boundary lies depends on the task and the literature.
Why does the softmax baseline sometimes fail to detect OOD examples?
The softmax function forces class probabilities to sum to one, so the maximum softmax value reflects the relative size of the logits rather than how far an input lies from the training data. An OOD input can produce large logits for one class and therefore a high maximum score, leading to confident but incorrect predictions.
What evaluation metrics are used for OOD detection?
The two most common metrics are AUROC (Area Under the Receiver Operating Characteristic curve), which summarizes performance across all thresholds, and FPR-at-95%-TPR, the fraction of OOD inputs accepted as in-distribution when 95% of in-distribution inputs are correctly retained. Both are threshold-independent summary statistics that allow comparison across methods and datasets.
Related methods
Sources
Hendrycks, D., & Gimpel, K. (2017). A baseline for detecting misclassified and out-of-distribution examples in neural networks. International Conference on Learning Representations.
Open publication reference