Prototype Fusion: A Training-Free Multi-Layer Approach to OOD Detection
Organizations: Missouri University of Science and Technology, Rolla, MO 65401, USA · Washington State University, Richland, WA 99354, USA
Abstract
Deep learning models are increasingly deployed in safety-critical applications, where reliable out-of-distribution (OOD) detection is essential to ensure robustness. Existing methods predominantly rely on the penultimate-layer activations of neural networks, assuming they encapsulate the most informative in-distribution (ID) representations. In this work, we revisit this assumption to show that intermediate layers encode equally rich and discriminative information for OOD detection. Based on this observation, we propose a simple yet effective model-agnostic approach that leverages internal representations across multiple layers. Our scheme aggregates features from successive convolutional blocks, computes class-wise mean embeddings, and applies L_2 normalization to form compact ID prototypes capturing class semantics. During inference, cosine similarity between test features and these prototypes serves as an OOD score--ID samples exhibit strong affinity to at least one prototype, whereas OOD samples remain uniformly distant. Extensive experiments on state-of-the-art OOD benchmarks across diverse architectures demonstrate that our approach delivers robust, architecture-agnostic performance and strong generalization for image classification. Notably, it improves AUROC by up to 4.41% and reduces FPR by 13.58%, highlighting multi-layer feature aggregation as a powerful yet underexplored signal for OOD detection, challenging the dominance of penultimate-layer-based methods. Our code is available at: https://github.com/sgchr273/cosine-layers.git.
Figures & tables
| Model | Method | iSUN | LSUN | Places | iNat | Textures | Average | ||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | ||
| ResNet-18 | MSP | 89.79 | 47.44 | 94.68 | 15.26 | 89.66 | 48.32 | 89.59 | 44.33 | 87.18 | 63.96 | 90.75 | 39.75 |
| MaxLogit | 90.08 | 52.84 | 94.63 | 25.82 | 89.65 | 55.06 | 89.37 | 51.19 | 86.35 | 73.86 | 90.74 | 46.60 | |
| Energy | 88.42 | 63.00 | 92.34 | 51.48 | 87.97 | 62.87 | 87.46 | 59.14 | 84.24 | 79.10 | 89.02 | 57.46 | |
| Mahalanobis | 86.86 | 51.32 | 80.99 | 53.84 | 84.80 | 49.93 | 80.25 | 58.48 | 92.64 | 34.99 | 86.61 | 46.26 | |
| GradNorm | 83.44 | 70.92 | 91.86 | 37.20 | 79.30 | 74.98 | 90.81 | 44.29 | 81.20 | 82.75 | 86.56 | 57.97 | |
| ID = CIFAR-10 | ID = CIFAR-100 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Model | Method | CIFAR-100 | SVHN | Average | CIFAR-10 | SVHN | Average | ||||||
| AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | ||
| ResNet-18 | MSP | 88.76 | 46.29 | 93.60 | 19.17 | 91.18 | 32.73 | 75.62 | 77.26 | 72.92 | 83.01 | 74.27 | 80.14 |
| MaxLogit | 88.09 | 53.99 | 94.36 | 20.86 | 91.22 | 37.42 | 72.75 | 84.39 | 67.27 | 90.25 | 70.01 | 87.32 | |
| Energy | 85.04 | 64.90 | 93.69 | 29.20 | 89.37 | 47.05 | 66.38 | 86.81 | 58.26 | 91.68 | 62.32 | 89.25 | |
| Mahalanobis | 82.11 | 59.59 | 94.12 | 29.00 | 88.12 | 44.30 | 70.44 | 78.46 | 77.92 | 61.76 | 74.18 | 70.11 | |
| Model | Method | SUN | Places | iNat | Textures | Average | |||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | AUROC | FPR | ||
| ResNet-50 | MSP | 79.25 | 79.48 | 77.48 | 78.59 | 84.65 | 62.69 | 74.78 | 87.76 | 79.04 | 77.13 |
| MaxLogit | 74.78 | 85.81 | 72.64 | 85.90 | 80.25 | 76.47 | 69.25 | 91.74 | 74.23 | 84.98 | |
| Energy | 50.82 | 89.72 | 50.55 | 90.23 | 51.27 | 87.51 | 48.57 | 94.28 | 50.30 | 90.44 | |
| Mahalanobis | 79.60 | 54.97 | 77.26 | 65.66 | 90.48 | 29.89 | 87.13 | 53.09 | 83.62 | 50.90 | |
| GradNorm | 30.01 | 94.09 | 29.56 | 95.31 | 30.72 | 90.89 | 39.25 | 91.06 | 32.38 | 92.84 | |
OOD Detection
Out-of-distribution (OOD) detection identifies inputs unlike a model’s training data so systems can flag uncertainty, reject inputs, or adapt safely.
See all 215 papers