Table of Contents
Fetching ...

Prototype Fusion: A Training-Free Multi-Layer Approach to OOD Detection

Shreen Gul, Mohamed Elmahallawy, Ardhendu Tripathy, Sanjay Madria

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.

Prototype Fusion: A Training-Free Multi-Layer Approach to OOD Detection

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.
Paper Structure (23 sections, 11 equations, 5 figures, 3 tables, 1 algorithm)

This paper contains 23 sections, 11 equations, 5 figures, 3 tables, 1 algorithm.

Figures (5)

  • Figure 1: Overview of the proposed training-free OOD detector. A pretrained CNN is tapped at layers $\ell_1$–$\ell_3$. ID calibration images are passed through the network, and per-layer features are global-average-pooled and $L_2$-normalized to form $K$ class prototypes (green regions). For a test image (ID or OOD), we compute cosine similarity between its features and each layer's prototypes (green arrows for ID, red arrows for OOD). At each layer, we retain the maximum class-wise similarity, and these per-layer maxima are averaged to produce an ID affinity score, with $\text{OODScore} = 1 - \text{affinity}$. The heatmaps on the right show that ID samples yield strong, consistent similarities across layers and classes, whereas OOD samples produce weaker and less coherent similarity patterns.
  • Figure 2: Effect of calibration set size on AUROC (top row) and false positive rate (bottom row) for CIFAR-10, CIFAR-100, and ImageNet-1k.
  • Figure 3: AUROC and FPR using the penultimate layer vs. the last three layers across three ID datasets: CIFAR-10 (Exp1), CIFAR-100 (Exp2), and ImageNet-1K (Exp3).
  • Figure 4: Impact of weighting schemes across layers on overall detection performance.
  • Figure 5: Per-layer cosine similarity scores for the last three layers of ResNet-18 on ID data (CIFAR-10)and four OOD datasets (SVHN, Textures, LSUN, Places).