Out-of-Distribution Detection using Neural Activation Prior
Weilin Wan, Weizhong Zhang, Quan Zhou, Fan Yi, Cheng Jin
TL;DR
The paper introduces Neural Activation Prior (NAP), a simple, plug-and-play prior for out-of-distribution (OOD) detection that leverages within-channel activation distributions in the penultimate CNN layer before global pooling. The core idea is to compare, per channel $j$, the ratio $\frac{\max(\mathbf{A}_j)}{\text{Mean}(\mathbf{A}_j) + \epsilon}$ and aggregate across channels to form $S_{\text{NAP}}(x;f)$, with a Transformer analogue using CLS-token attention, $S_{\text{NAP}}^{\text{Former}} = \text{Max}(A)$. The method is orthogonal to existing post-pooling priors and is designed to be combined with scoring functions like the Energy score via $S_{\text{NAP-E}}(x;f,w) = -E(x;f)^w \cdot S_{\text{NAP}}(x;f)^{1-w}$, with $w$ chosen through pseudo-OOD data transformations. Empirically, NAP achieves state-of-the-art or strong results on CIFAR-10/100 and ImageNet benchmarks, extends effectively to Vision Transformers, and preserves in-distribution accuracy while improving OOD detection. This work suggests that rich pre-pooling activation statistics contain transferable OOD signals and can broadly enhance reliability in real-world applications.
Abstract
Out-of-distribution detection (OOD) is a crucial technique for deploying machine learning models in the real world to handle the unseen scenarios. In this paper, we first propose a simple yet effective Neural Activation Prior (NAP) for OOD detection. Our neural activation prior is based on a key observation that, for a channel before the global pooling layer of a fully trained neural network, the probability of a few neurons being activated with a large response by an in-distribution (ID) sample is significantly higher than that by an OOD sample. An intuitive explanation is that for a model fully trained on ID dataset, each channel would play a role in detecting a certain pattern in the ID dataset, and a few neurons can be activated with a large response when the pattern is detected in an input sample. Then, a new scoring function based on this prior is proposed to highlight the role of these strongly activated neurons in OOD detection. Our approach is plug-and-play and does not lead to any performance degradation on ID data classification and requires no extra training or statistics from training or external datasets. Notice that previous methods primarily rely on post-global-pooling features of the neural networks, while the within-channel distribution information we leverage would be discarded by the global pooling operator. Consequently, our method is orthogonal to existing approaches and can be effectively combined with them in various applications. Experimental results show that our method achieves the state-of-the-art performance on CIFAR benchmark and ImageNet dataset, which demonstrates the power of the proposed prior. Finally, we extend our method to Transformers and the experimental findings indicate that NAP can also significantly enhance the performance of OOD detection on Transformers, thereby demonstrating the broad applicability of this prior knowledge.
