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.
翻译:分布外检测(OOD)是机器学习模型在实际部署中处理未知场景的关键技术。本文首先提出一种简单而有效的神经激活先验(NAP)用于OOD检测。该先验基于一个关键观察:在完全训练好的神经网络中,全局池化层前的某一通道内,分布内(ID)样本激活少数神经元产生大响应的概率显著高于OOD样本。直观解释是,针对ID数据集完全训练的模型,每个通道负责检测ID数据集中特定模式,当输入样本检测到该模式时,少数神经元会以强响应被激活。基于此先验,我们提出新的评分函数,突出这些强激活神经元在OOD检测中的作用。该方法即插即用,不会导致ID数据分类性能下降,且无需额外训练或从训练集/外部数据集获取统计信息。值得注意的是,现有方法主要依赖神经网络全局池化后的特征,而我们所利用的通道内分布信息会被全局池化算子丢弃。因此,本方法与现有方法正交,可有效集成至各类应用。实验结果表明,本方法在CIFAR基准测试和ImageNet数据集上达到最优性能,验证了所提先验的有效性。最后,我们将方法扩展至Transformer模型,实验表明NAP能显著提升Transformer上的OOD检测性能,展示了该先验知识的广泛适用性。