Kernel PCA for Out-of-Distribution Detection
Kun Fang, Qinghua Tao, Kexin Lv, Mingzhen He, Xiaolin Huang, Jie Yang
TL;DR
This work tackles out-of-distribution (OoD) detection by applying Kernel PCA (KPCA) to penultimate DNN features, addressing PCA's linearity limitation with two task-specific, explicit mappings. The Cosine Kernel KPCA (CoP) uses a cosine normalization mapping, while the Cosine-Gaussian KPCA (CoRP) adds a Gaussian component via Random Fourier Features, yielding reconstruction errors that separate InD and OoD data efficiently. The approach achieves state-of-the-art OoD detection on CIFAR-10 and ImageNet-1K across multiple datasets with favorable inference cost ($O(1)$ for CoP and $O(M)$ for CoRP) compared to $O(N_{tr})$ for nearest-neighbor methods, and provides theoretical links between covariance-based and kernel KPCA. While manual kernel choices limit generality, the kernel perspective guides future learning of kernels (e.g., deep kernel learning) to further enhance robustness and scalability in real-world deployment.
Abstract
Out-of-Distribution (OoD) detection is vital for the reliability of Deep Neural Networks (DNNs). Existing works have shown the insufficiency of Principal Component Analysis (PCA) straightforwardly applied on the features of DNNs in detecting OoD data from In-Distribution (InD) data. The failure of PCA suggests that the network features residing in OoD and InD are not well separated by simply proceeding in a linear subspace, which instead can be resolved through proper non-linear mappings. In this work, we leverage the framework of Kernel PCA (KPCA) for OoD detection, and seek suitable non-linear kernels that advocate the separability between InD and OoD data in the subspace spanned by the principal components. Besides, explicit feature mappings induced from the devoted task-specific kernels are adopted so that the KPCA reconstruction error for new test samples can be efficiently obtained with large-scale data. Extensive theoretical and empirical results on multiple OoD data sets and network structures verify the superiority of our KPCA detector in efficiency and efficacy with state-of-the-art detection performance.
