Title: Kernel PCA for Out-of-Distribution Detection
Venue: NeurIPS 2024
Accepted: yes
Keywords: out-of-distribution detection

kernel principal component analysis

random Fourier features
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.

Kernel PCA for Out-of-Distribution Detection

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 taskspecific 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.

1 Introduction

With the rapid advancement of the powerful learning abilities of Deep Neural Networks (DNNs) [1, 2], the trustworthiness of DNNs in security-sensitive scenarios has attracted considerable attention in recent years [3]. Generally, samples from the training and test sets of DNNs are viewed as data from some In Distribution (InD) P in , while samples from other data sets are regarded as coming from a different distribution P out , i.e. , out-of-distribution (OoD) data. In the practical deployment, DNNs trained on InD data would inevitably encounter OoD data and thus yield unreliable results with potential risks. Therefore, detecting whether a new sample is from P in or P out has been a valuable research topic of trustworthy deep learning, namely OoD detection [4].

Existing OoD detection methods exploit different outputs from DNNs to unveil the hidden disparities between InD and OoD data, e.g. , logits [5], gradients [6] and features [7, 8]. In this work, we address OoD detection from a perspective of utilizing the feature spaces learned by the backbone of DNNs. To be specific, given a DNN f : R d → R c , f takes x ∈ R d as inputs and learns penultimate layer features z ∈ R m before the last linear layer. Principal Component Analysis (PCA) is investigated in [8] to calculate the reconstruction error in the z -space as the OoD detection score. That is, PCA is executed on the penultimate features of InD training samples and learns a linear subspace spanned by the principal components in the z -space. Then, given features ˆ z of an unknown sample ˆ x , one can obtain the reconstructed counterpart of ˆ z by projecting ˆ z to the linear subspace and re-projecting it back. The reconstruction error is computed as the Euclidean distance between ˆ z and the reconstructed counterpart. In [9], similar ideas are adopted with energy-based models using an

InD (CIFAR10)

OoD (LSUN)

OoD (iSUN)

2

4

6

Density

CIFAR10

LSUN

2

4

6

Density

CIFAR10

iSUN

InD (CIFAR10)

OoD (LSUN)

OoD (iSUN)

0.2

0.4

0.6

0.8

Density

CIFAR10

LSUN

0.2

0.4

0.6

0.8

Density

CIFAR10

iSUN

(a) T-SNE of z and PCA reconstruction errors.

(b) T-SNE of Φ( z ) and KPCA reconstruction errors.

auto-encoder structure, where the neural networks are trained from scratch and the reconstruction is conducted in the decoder. For good OoD detection performance, it is expected that InD features are compactly allocated along the linear principal components with high variances for capturing most of the informative patterns of InD data, leading to small reconstruction errors, while OoD features are not supposed to be well matched with the learned subspace, causing large reconstruction errors.

However, it has been empirically observed in [8] that such PCA reconstruction errors alone cannot distinctively differentiate OoD data from InD data, leading to poor detection performance of PCA in the z -space. Nevertheless, [8] did not take further explorations on the reasons behind, and instead proposed a practical fusion trick to boost PCA by multiplying with other existing powerful detection scores. Therefore, in this work, more in-depth analyses are undertaken to improve the limitations of PCA for OoD detection with insightful understandings on the distribution of InD and OoD features. It is widely acknowledged that PCA falls inferior in dealing with those linearly-inseparable data, which inspires us to explore the non-linearity existing in the z -space of InD and OoD features under the help of the celebrated Kernel PCA (KPCA).

KPCA has long been a powerful technique in learning the non-linear patterns of data [11, 12]. By deploying KPCA, a non-linear feature mapping Φ is imposed on the z -space in this setup, so that the linear inseparability can be alleviated in the mapped Φ( z ) -space. KPCA is generally conducted through a kernel function k induced by the feature mapping, i.e. , k ( z 1 , z 2 ) = ⟨ Φ( z 1 ) , Φ( z 2 ) ⟩ , in order to avoid explicit calculations in the mapped Φ( z ) -space. In most cases, researchers have no prior on the unknown non-linear data distribution, e.g. , the non-linearity in the z -space of InD and OoD features. Therefore, finding an appropriate k or Φ that well adapts the data always remains a non-trivial issue for KPCA. For example, the mostly common Gaussian kernel is shown to be unable to separate the InD and OoD features, and leads to terrible OoD detection performance, see details in Appendix C. In addition, KPCA also faces the challenge of calculating and storing the N tr × N tr kernel matrix on millions of training samples with a very large size N tr , which significantly hinders its application in practical tasks with a huge amount of data.

The proposed KPCA detection method well addresses the aforementioned issues of KPCA for OoD detection. On the one hand, to better understand the non-linear patterns in InD and OoD features, we take a kernel perspective on an existing OoD detector [7], which searches k -th Nearest Neighbors (KNN) on the ℓ 2 normalized features z . By decoupling and analyzing key components of the KNN method, we acquire two effective kernels, a cosine kernel and a cosine-Gaussian kernel, for our KPCA detector to promote the linear separability between InD and OoD features in the subspace of the principal components, leading to substantially improved distinguishable KPCA reconstruction errors, as shown in Figure 1. On the other hand, for a computationally-friendly implementation, two explicit feature mappings Φ induced from the cosine and cosine-Gaussian kernels are executed on the original features z , followed by PCA in the mapped Φ( z ) -space to obtain the reconstruction errors without calculations on the kernel matrix. Specifically, the celebrated Random Fourier Features (RFFs) [13] are introduced to approximate the Gaussian kernel, allowing an O ( M ) computation

complexity in inference, which significantly outperforms the O ( N tr ) computation complexity of the KNN [7] and the kernel-matrix-based KPCA ( M is the number of RFFs and M ≪ N tr ).

Extensive experiments verify the effectiveness of the devoted two kernels, which we hope could bring inspirations for the research community in exploring the non-linearity in InD and OoD data from a kernel perspective. For example, the two kernels can even serve as a beneficial prior on advocating learning more and stronger kernels for OoD detection. In addition, we supplement our method with its implementation via the kernel matrix, and illustrate the advantageous effectiveness and efficiency of explicit feature mappings in Section 6. The contributions of this work are summarized below:

To the best of our knowledge, this is the first work that explores suitable kernels to seize the non-linearity in InD and OoD features in the post-hoc stage on well-trained DNNs.

Two task-specific kernels are carefully devised for OoD detection. Particularly, two explicit feature mappings induced from the kernels are adopted for the KPCA detector, and lead to separable KPCA reconstruction errors with significantly-reduced complexity in inference.

Theoretical and experimental comparisons indicate the effects of kernels in our KPCA detector with SOTA detection performance and remarkably reduced time complexity.

In the remainder of this work, related works and research backgrounds are outlined in Section 2 and Section 3, respectively. Section 4 delves into details of the proposed KPCA detector. Comparison experiments with prevailing OoD detection methods and KPCA via kernel functions are presented in Section 5 and Section 6, respectively. Conclusions and limitations are drawn in Section 7.

2 Related work

Generally, out-of-distribution detection has been formulated as a binary classification problem including a decision function D ( · ) and a scoring function S ( · ) :

The scoring function S ( · ) assigns a score S ( ˆ x ) for a new sample ˆ x . If S ( ˆ x ) is greater than a threshold s , the decision function D ( · ) would view ˆ x as an InD sample, and vice versa. The key to effectually detecting OoD samples is a well-designed scoring function. Existing OoD detectors adopt different outputs from DNNs and design justified scores to measure the disparity between InD and OoD data.

Logits-based detectors exploit the abnormal responses reflected in the predictive logits or probabilities from DNNs to detect OoD data. Typical methods adopt either the maximum logits [14] or probability [15, 16] or the energy function on logits [5] as the detection score.

Gradients-based methods investigate differences on gradients w.r.t InD and OoD data for OoD detection. For example, gradient norms [6] or low-dimensional representations [17] are studied to devise the detection score.

Features-based detectors try to capture the feature information causing over-confidence of OoD predictions in different ways. Feature clipping [18, 19, 20, 21, 22], feature distances [23, 7, 24], feature norms [25], rank-1 features [26], feature subspace [8], etc., have been explored with excellent performance.

Aside from methods above, other existing OoD detectors cover the training regularization [27, 28], the ensemble technique [29] and theoretical understandings [30, 31]. Refer to Appendix A for more detailed descriptions on the compared methods in experiments [32, 33, 34, 35].

3 Background

3.1 PCA for OoD detection

The PCA detector with the reconstruction error as the detection score is summarized firstly. Given the penultimate features z i ∈ R m learned by a well-trained DNN f : R d → R c of the InD training

data x i ∈ R d , i = 1 , · · · , N tr , the covariance matrix Σ is calculated as:

Through the eigendecomposition Σ = U Λ U ⊤ , the dimensionality reduction matrix U q ∈ R m × q is obtained by taking the first q columns of the eigenvector matrix U w.r.t the topq largest eigenvalues.

In inference, given a new sample ˆ x ∈ R d and its feature ˆ z ∈ R m from the DNN f , the reconstruction error is computed as:

By projecting centralized ( ˆ z -µ ) to the U q -subspace and re-projecting back, we can obtain the reconstructed features U q U ⊤ q ( ˆ z -µ ) and the reconstruction error e ( ˆ x ) , which then can be set as the OoD detection score: S ( ˆ x ) = -e ( ˆ x ) . An ideal case is that U q contains informative principal components of InD data and causes projections of OoD data far away from that of InD data, leading to separable reconstruction errors between OoD and InD data.

3.2 Random Fourier features

A concise description is firstly given on the Random Fourier Features (RFFs) [13], which will be adopted in our method later. RFFs are proposed to approximate the kernel function so as to alleviate the heavy computation cost in large-scale kernel machines. In kernel methods, an N × N kernel matrix w.r.t N samples requires O ( N 2 ) kernel manipulations, O ( N 2 ) space complexity and O ( N 3 ) time complexity to calculate the inverse of the kernel matrix, which leads to overwhelmed computation costs for a large data size N . Therefore, RFFs are introduced by building an explicit feature mapping to directly approximate the kernel function for efficient kernel machines on large-scale data.

RFFs are built on the Bochner's theorem [36]: A continuous and shift-invariant kernel k ( z 1 , z 2 ) = k ( z 1 -z 2 ) on R m is positive definite if and only if k ( · ) is the Fourier transform of a non-negative measure. An explicit feature mapping ϕ RFF induced from the kernel k is derived in [13]:

where ω 1 , · · · , ω M ∈ R m are i.i.d. sampled from the Fourier transform of k ( · ) , and u 1 , · · · , u M ∈ R are i.i.d. sampled from a uniform distribution U (0 , 2 π ) . For example, the sampling distribution for ω i of a Gaussian kernel function k gau = e -γ ∥ z 1 -z 2 ∥ 2 2 is ω ∼ N (0 , √ 2 γ I m ) . Such a feature mapping ϕ RFF satisfies k gau ( z 1 , z 2 ) ≈ ϕ RFF ( z 1 ) ⊤ ϕ RFF ( z 2 ) and is known as the random Fourier features (RFFs) mapping. Refer to [13] for a detailed convergence analysis. RFFs have been widely utilized in kernel learning [37], optimization [38], etc.

4 Methodology

As empirically observed in [8], the aforementioned PCA reconstruction error in the z -space is not an effective score in detecting OoD data from InD data. We propose that the reason behind is possibly due to the linearly-inseparable features of InD and OoD data, as shown in Figure 1a. To address this issue, we propose to explore the non-linearity in z -space via kernel PCA. Then, through a kernel perspective on an existing KNN detector [7], we put forward two efficacious kernels that well characterize the non-linear patterns in z -space of InD and OoD data: a cosine kernel (Section 4.1) and a cosine-Gaussian kernel (Section 4.2). Particularly, we adopt two explicit feature mappings Φ induced from the two kernels, and execute PCA in the mapped Φ( z ) -space, which leads to an informative principal subspace and distinct reconstruction errors for efficacious OoD detection.

4.1 Cosine kernel

In the KNN detector [7], the nearest neighbor searching is executed on the ℓ 2 -normalized penultimate features, i.e. , z ∥ z ∥ 2 . In inference, given a new sample ˆ x , its feature ˆ z is firstly normalized as ˆ z ∥ ˆ z ∥ 2 ,

then the negative of its ( k -th) shortest ℓ 2 distance to the ℓ 2 -normalized features z i ∥ z i ∥ 2 of training data is set as the detection score:

The ablations in KNN demonstrate the indispensable significance of the ℓ 2 -normalization: the nearest neighbor searching directly on z shows a notably drop in detection performance. The critical role of the ℓ 2 -normalization in KNN attracts our attention in the sense of kernel. From a kernel perspective, the ℓ 2 -normalization is exactly the non-linear feature mapping ϕ cos inducing the cosine kernel k cos :

It indicates that a justified ϕ cos ( z ) -space with such non-linear mapping, instead of the original z -space, contributes to the success of nearest neighbor searching in detecting OoD.

Notice that the key of KPCA for OoD detection lies in an appropriate non-linear feature space that captures the non-linearity in InD and OoD features, either through the kernel k or the associated explicit feature mapping Φ . Motivated by the KNN detector, we apply Φ( · ) ≜ ϕ cos ( · ) as the feature mapping in KPCA to introduce non-linearity. Then, PCA is executed on mapped features ϕ cos ( z ) , following the procedures described in Section 3.1. All the features z are now mapped to Φ( z ) to formulate the covariance matrix Σ Φ , for computing non-linear principal components with matrix U Φ q and the corresponding reconstruction error e Φ . This detection scheme is dubbed as CoP ( Co sine mapping followed by P CA), as shown in Algorithm 1. An in-depth analysis on the effect of the normalization of the cosine kernel is left in Appendix C.1.

4.2 Cosine-Gaussian kernel

The success of KNN (Equation (5)) suggests that the ℓ 2 distance on z ∥ z ∥ 2 is effective in distinguishing OoD data from InD data. In other words, the ℓ 2 distance relation between samples in the ϕ cos -space preserves useful information that benefits the separation of OoD data from InD data. This motivates us to seek non-linear feature spaces that can retain the ℓ 2 distance relation. Hence, we propose to introduce KPCA with non-linearity built upon ϕ cos ( z ) , through which the useful ℓ 2 distance in ϕ cos -space can be preserved to further separate InD and OoD data.

In this regard, we deploy the shift-invariant Gaussian kernel to keep the ℓ 2 distance information:

The feature mapping associated with k gau is infinite-dimensional, but it can be efficiently approximated through random Fourier features (RFFs, [13]), i.e. , ϕ RFF defined in Equation (4). In this way, the inner product of two mapped samples ϕ RFF ( z 1 ) ⊤ ϕ RFF ( z 2 ) provides the approximate Gaussian kernel, so that we can leverage the RFFs mapping ϕ RFF to preserve the ℓ 2 distance information through the Gaussian kernel.

Hence, a cosine-Gaussian kernel is adopted for OoD detection, as the Gaussian kernel k gau (or ϕ RFF ) is imposed on top of the cosine kernel k cos (or ϕ cos ), further exploiting the ℓ 2 distance relationships beyond the ϕ cos -space for OoD detection. As we work with the explicit feature mapping, the nonlinearity to z is achieved by Φ( · ) ≜ ϕ RFF ( ϕ cos ( · )) . With mappings ϕ RFF ( ϕ cos ( z )) , PCA is then executed to compute the reconstruction errors for OoD detection. This detection scheme is dubbed as CoRP ( Co sine and R FFs mappings followed by P CA). Algorithm 1 illustrates the complete procedure of the proposed CoP and CoRP for OoD detection. Alternative choices for more kernels are exploited in Appendix C.2.

To warp up, we devise two effective feature mappings induced from a cosine kernel and a cosineGaussian kernel to promote the separability of InD data and OoD data in non-linear feature spaces, inspired by effectiveness of the ℓ 2 normalization and the ℓ 2 distance from a kernel perspective on the KNN detector [7]. Our proposed two feature mappings well characterize the non-linearity in penultimate features z of DNNs between InD and OoD data, enabling PCA to extract an informative subspace w.r.t the mapped features through principal components and the reconstruction errors.

Algorithm 1 Kernel PCA for Out-of-Distribution Detection 1: if CoP then 2: Φ( · ) ← ϕ cos ( · ) , ϕ cos ( z ) = z ∥ z ∥ 2 . 3: else if CoRP then 4: Sampling ω i ∼ N (0 , √ 2 γ I m ) , i = 1 , · · · , M . 5: Sampling u i ∼ U (0 , 2 π ) , i = 1 , · · · , M . 6: Φ( · ) ← ϕ RFF ( ϕ cos ( · )) . 7: end if 8: Calculating the covariance matrix in the mapped Φ( z ) -space: Σ Φ = ∑ N tr i =1 (Φ( z i ) -µ Φ )(Φ( z i ) -µ Φ ) ⊤ , µ Φ = 1 N tr ∑ N tr i =1 Φ( z i ) . 9: Applying eigendecomposition: Σ Φ = U Φ Λ Φ U Φ ⊤ . 10: Taking the first q columns of U Φ w.r.t the topq largest eigenvalues in Λ Φ : U Φ q = U Φ [: , : q ] . Ensure: Dimensionality-reduction matrix U Φ q . 11: Given a new sample ˆ x and its features ˆ z . 12: Calculating the reconstruction error: e Φ ( ˆ x ) = ∥ ∥ ∥ U Φ q U Φ ⊤ q (Φ( ˆ z ) -µ Φ ) -(Φ( ˆ z ) -µ Φ ) ∥ ∥ ∥ 2 . Ensure: Reconstruction error e Φ .

Computation complexity In our method, given any new sample ˆ x with the penultimate features ˆ z in inference, to compute the reconstruction error e Φ ( ˆ x ) , we only need the feature mapping Φ , the projection matrix U Φ q and the mean mapped training feature vector µ Φ . Both U Φ q and µ Φ can be pre-calculated and stored in preparation for inference. Therefore, the entire computation cost of CoP and CoRP comes from the construction of the explicit feature mapping Φ on new features ˆ z .

For CoP, its feature mapping ϕ cos is an in-place operation and does not require additional computations. Therefore, the time and memory complexity of CoP is O (1) .

For CoRP, the feature mapping ϕ RFF of the Gaussian kernel requires 2 M samplings for ω i and u i , respectively, and M dot-products and M additions. Accordingly, the time and memory complexity of CoRP is O ( M ) .

In contrast, regarding the Equation (5) of the KNN detector, all the training features have to be stored at hand and iterated in inference, which implies a heavy O ( N tr ) time and memory complexity. The O (1) / O ( M ) of CoP/CoRP significantly outperforms the O ( N tr ) of KNN ( M ≪ N tr ). Detailed empirical comparisons are provided in Section 5.1.

In the following, Section 5 exhibits the SOTA performance of our KPCA detector over multiple prevailing detection methods. Section 6 gives an analytical discussion between our covariance-based KPCA and classic KPCA via kernel functions for OoD detection. Due to space limitation, more in-depth investigations on the kernel properties are left in Appendix C, covering ablation studies (Appendix C.1), alternative kernels (Appendix C.2) and sensitivity analysis (Appendix C.3).

5 Experiments on OoD detection

In experiments, our KPCA-based detectors, CoP and CoRP, are firstly compared with KNN [7] in Section 5.1, and show stronger detection performance and cheaper computation costs. In Section 5.2, CoP and CoRP are further compared with the regularized PCA reconstruction error [8], and achieve SOTA OoD detection performance over various prevailing methods. The source code of this work has been publicly released 1 . All the experiments are executed on 1 NVIDIA GeForce RTX 3090 GPU.

Datasets Experiments are executed on the commonly-used small-scale CIFAR10 [39] and largescale ImageNet-1K benchmarks [40], following the settings in [7, 8]. For CIFAR10 as InD, OoD data sets include SVHN [41], LSUN [42], iSUN [43], Textures [44] and Places365 [45]. For ImageNet-1K as InD, OoD data sets contain iNaturalist [46], SUN [47], Places [45] and Textures [44].

Metrics For the evaluation metrics, we employ the commonly-used (i) False Positive Rate of OoD samples with 95% true positive rate of InD samples (FPR), and (ii) Area Under the Receiver Operating Characteristic curve (AUROC). The average FPR95 and AUROC values over the selected multiple OoD data sets are viewed as the final comparison metrics.

5.1 Comparisons with nearest neighbor searching

The comparisons with KNN [7] cover both the benchmarks. Following the setups in KNN, for fair comparisons, we evaluate models trained via the standard cross-entropy loss and models trained via the supervised contrastive learning [49], and adopt the same checkpoints released by KNN: ResNet18 [50] on CIFAR10 and ResNet50 on ImageNet-1K. Here, the scoring function of CoP and CoRP is S ( ˆ x ) = -e Φ ( ˆ x ) in Algorithm 1.

Table 1 presents empirical results of ResNet50 on the ImageNet-1K benchmark. In the standard training, our CoRP shows superior detection performance over KNN with lower FPR and higher AUROC values averaged over multiple OoD data sets. In supervised contrastive learning, both CoP and CoRP outperform other baseline results on each OoD data set. These results show that the proposed KPCA exploring non-linear patterns is more advantageous than the nearest neighbor searching and all compared methods. Besides, the further improvements of CoRP over CoP also verify the effectiveness of the distance-preserving property of the Gaussian kernel k gau on top of the cosine kernel k cos for OoD detection.

On the other hand, regarding the computational complexity in inference, Table 2 empirically shows the superior O (1) / O ( M ) time and memory complexity of CoP/CoRP over the O ( N tr ) of KNN, including: (i) the inference time of the nearest neighbor search in KNN and the reconstruction error calculation in CoP/CoRP; (ii) the storage of the InD training features in KNN and the U Φ q and µ Φ in CoP/CoRP. To be specific, for KNN, storing and iterating all the N tr = 1 , 281 , 167 features of ImageNet-1K training set requires nearly 20 GiB and 16 ms, respectively, while our CoP and CoRP directly compute the reconstruction error for each new sample with the pre-calculated projection

matrix and the mean vector from the training data, resulting in a much higher processing speed and far less storage. The number of RFFs M for CoRP in this experiment is M = 4 , 096 ( M ≪ N tr ).

In addition, KPCA also outperforms KNN on the CIFAR10 benchmark with improved OoD detection performances, which we leave to Appendix B for more details.

5.2 Comparisons with regularized reconstruction errors

In [8], to alleviate the weak detection performance of PCA reconstruction error e ( ˆ z ) of Equation (3), the authors proposed to regularize e ( ˆ z ) by the feature norm ∥ ˆ z ∥ 2 and a fusion strategy to boost its detection performance by introducing existing OoD scores. Firstly, the regularized reconstruction

⊤

error e reg ( ˆ z ) is calculated in the original z -space as : e reg ( ˆ z ) = ∥ U q U q ( ˆ z -µ ) -( ˆ z -µ ) ∥ 2 ∥ ˆ z ∥ 2 . Then, the authors claimed that such a regularized version e reg ( ˆ z ) is still insufficient for OoD detection, and designed a fusion strategy to combine e reg with other existing OoD scores. For example, to fuse e reg with the Energy [5] score, the final scoring function is S ( ˆ x ) = (1 -e reg ( ˆ z )) · S Energy ( ˆ z ) .

In this section, we show that our KPCA reconstruction error e Φ outperforms the regularized PCA reconstruction error e reg under the same fusion framework. Following the settings in [8], for a fair comparison, the fused OoD scores include MSP [15], Energy [5], ReAct [18] and BATS [19]. The detection experiments are executed on the ImageNet-1K benchmark with pre-trained ResNet50 and MobileNet [51] checkpoints from PyTorch [52].

Table 3 presents the comparisons between [8] and ours on the ImageNet-1K benchmark of ResNet50. When fused with MSP, Energy and BATS, both the KPCA-based CoP and CoRP outperform the regularized reconstruction error [8] on almost all the OoD data sets with substantially improved FPR and AUROC values. Specifically, when fused with the ReAct method [18], the CoRP achieves new SOTA OoD detection performance among various prevailing detectors. Experiments on MobileNet also show superior performance of CoP and CoRP, see details in Appendix B.

All these experiment results indicate that an appropriately mapped Φ( z ) -space benefits the OoD detection, as the non-linearity in z -space gets alleviated by the feature mapping Φ . Our work provides 2 viable selections for Φ with empirical validations, which we hope could attract attentions towards the non-linearity in InD and OoD features for the research community from a kernel perspective.

6 Analytical discussions with KPCA via kernel functions

In CoP and CoRP, KPCA is executed with the covariance matrix of mapped features Φ( z ) . In contrast, in the classic KPCA [11, 12], such feature mappings Φ are not explicitly given, and it rather works with a kernel function applied to original features z . In this section, we supplement our covariance-based KPCA with its kernel function implementation, including theoretical discussions and empirical comparisons on OoD detection. Our CoP and CoRP are shown to be more effective and efficient than their counterparts that employ kernel functions.

In the classic KPCA, the kernel trick enables projections to the principal subspace via kernel functions without calculating Φ . However, how to map the projections in the principal subspace back to the original z -space remains a non-trivial issue, known as the pre-image problem [53], which makes it problematic to calculate reconstructed features via kernel functions. To address this issue, the following Proposition 1 shows a flexible way to directly calculate reconstruction errors without building reconstructed features, so as to apply the kernel trick, shown in the subsequent Proposition 2.

Proposition 1. The KPCA reconstruction error e Φ ( ˆ z ) can be represented as the norm of features projected in the residual subspace, i.e., the U Φ p -subspace with U Φ = [ U Φ q , U Φ p ] :

Proposition 1 implies that the reconstruction error equals to the norm of projections in the residual U Φ p -subspace, i.e. , the subspace consisting of those principal components that are not kept, see proofs in Appendix D. Accordingly, as typically done in the classic KPCA, we can introduce a kernel function to perform dimension reduction, but to the residual subspace, and then calculate the norms of the reduced features as the reconstruction error, illustrated by Proposition 2.

Given a kernel function k ( · , · ) : R m × R m → R , we have a kernel matrix K ∈ R N tr × N tr on training data with K i,j = k ( z i , z j ) , and a vector k ˆ z ∈ R N tr with the i -th element k ( z i , ˆ z ) for a new sample ˆ z . Proposition 2 shows how to calculate the KPCA reconstruction error via the kernel function k .

Proposition 2. The KPCA reconstruction error e k ( ˆ z ) w.r.t a kernel function k can be calculated as:

where A ∈ R N tr × l includes l eigenvectors of the kernel matrix K w.r.t the topl smallest eigenvalues.

According to Proposition 2, now CoP and CoRP can be implemented via kernel functions. For CoP, we just directly apply the cosine kernel function k cos on features z to compute the kernel matrix K and the projection matrix A , so as to obtain e k ( ˆ z ) following Equation (9). For CoRP, we should adopt the Gaussian kernel function k gau on the ℓ 2 -normalized inputs z ∥ z ∥ to calculate K , A and

2

e k ( ˆ z ) . Figure 2 shows comparisons on the detection performance between CoP/CoRP and their kernel function implementations.

In Figure 2, the detection performance of KPCA with kernel functions is evaluated by varying the explained variance ratio of the kernel matrix K . The larger the explained variance ratio, the smaller the dimension l of A . The best detection results achieved by CoP/CoRP are illustrated as the dashed lines. Clearly, regarding the OoD detection performance, reconstruction errors e k calculated by kernel functions are less effective than those calculated explicitly in the mapped Φ( z ) -space.

Aside from the detection performance, KPCA with kernel functions is far less computationally efficient than CoP/CoRP in two aspects. On the one hand, the time expense of eigendecomposition on the N tr × N tr kernel matrix K by the former is more expensive than that on the m × m or M × M covariance matrix Σ Φ by the latter, since N tr ≫ M and N tr ≫ m . For example, on the ImageNet-1K benchmark with MobileNet, these settings are N tr = 1 , 281 , 167 , M = 2560 and m = 1280 , on which KPCA with kernel functions is actually nearly prohibitive. On the other hand, in the inference stage, KPCA via kernel functions yet requires an O ( N tr ) time and memory complexity in calculating k ˆ z , as all the training data has to be stored and iterated, which is much higher than the O (1) / O ( M ) complexity of our CoP/CoRP.

0.95

0.96

0.97

0.98

0.99

1.0

explained variance ratio of

K

25

45

65

85

FPR95 (%)

cosine kernel

CoP

0.8

0.85

0.9

0.95

0.99

explained variance ratio of

K

cosine-Gaussian kernel

CoRP

7 Conclusion

As PCA reconstruction errors fail to distinguish OoD data from InD data on the penultimate features z of DNNs, kernel PCA is introduced for its non-linearity in the manner of employing explicit feature mappings. To find appropriate kernels that can characterize the non-linear patterns in InD and OoD features, we take a kernel perspective to decouple and analyze key components of an existing KNN detector [7], and thus propose a cosine kernel and a cosine-Gaussian kernel for KPCA. Specifically, two explicit feature mappings Φ( · ) induced from the two kernels are leveraged on original features z . For the cosine kernel, its explicit feature mapping can be directly obtained. For the Gaussian kernel, we adopt the celebrated random Fourier features to approximate the Gaussian kernel. The mapped Φ( z ) -space enables PCA to extract principal components that well separate InD and OoD data, leading to distinguishable reconstruction errors. Extensive empirical results have verified the improved effectiveness and efficiency of the proposed KPCA with new SOTA OoD detection performance. Besides, more in-depth analyzes are drawn on the individual effects of the cosine kernel and the Gaussian kernel, and the involved multiple hyper-parameters. In addition, theoretical discussions and associated experiments are provided to bridge the relationships between our covariance-based KPCA and its kernel function implementation so as to further illustrate the advantages of our method.

One limitation of the KPCA detector is that the two specific kernels are still manually selected with carefully-tuned parameters. It remains a valuable topic in the OoD detection task whether the parameters of kernels could be learned from data according to some optimization objective. For example, deep kernel learning [54] could be considered as an alternative choice so as to pursue stronger kernels that can better characterize InD and OoD with enhanced detection performance by an additional learning step on the features. We hope that the proposed two effective kernels verified empirically in our work could benefit the research community as a solid example for future studies.

Acknowledgments and Disclosure of Funding

This work is jointly supported by National Natural Science Foundation of China (62376153, 62376155), and Shanghai Municipal Science and Technology Research Major Project (2021SHZDZX0102).

Societal impacts

The societal impacts of this work are mainly positive, as it aims at detecting OoD samples in the inference or deployment stage of DNNs, which benefits researches in trustworthy deep learning. Through our work, we hope that new inspirations on the non-linearity in data could be drawn from a kernel perspective so as to highlight the safety issue in real-world machine learning applications.

References

Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising diffusion probabilistic models. Advances in neural information processing systems, 33:6840-6851, 2020.

Long Ouyang, Jeffrey Wu, Xu Jiang, Diogo Almeida, Carroll Wainwright, Pamela Mishkin, Chong Zhang, Sandhini Agarwal, Katarina Slama, Alex Ray, et al. Training language models to follow instructions with human feedback. Advances in Neural Information Processing Systems, 35:27730-27744, 2022.

Clark Barrett, Brad Boyd, Elie Bursztein, Nicholas Carlini, Brad Chen, Jihye Choi, Amrita Roy Chowdhury, Mihai Christodorescu, Anupam Datta, Soheil Feizi, et al. Identifying and mitigating the security risks of generative ai. Foundations and Trends® in Privacy and Security, 6(1):1-52, 2023.

Jingkang Yang, Kaiyang Zhou, Yixuan Li, and Ziwei Liu. Generalized out-of-distribution detection: A survey. International Journal of Computer Vision, pages 1-28, 2024.

Weitang Liu, Xiaoyun Wang, John Owens, and Yixuan Li. Energy-based out-of-distribution detection. Advances in neural information processing systems, 33:21464-21475, 2020.

Rui Huang, Andrew Geng, and Yixuan Li. On the importance of gradients for detecting distributional shifts in the wild. Advances in Neural Information Processing Systems, 34:677689, 2021.

Yiyou Sun, Yifei Ming, Xiaojin Zhu, and Yixuan Li. Out-of-distribution detection with deep nearest neighbors. In International Conference on Machine Learning, pages 20827-20840. PMLR, 2022.

Xiaoyuan Guan, Zhouwu Liu, Wei-Shi Zheng, Yuren Zhou, and Ruixuan Wang. Revisit pcabased technique for out-of-distribution detection. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pages 19431-19439, 2023.

Francesco Tonin, Arun Pandey, Panagiotis Patrinos, and Johan AK Suykens. Unsupervised energy-based out-of-distribution detection using stiefel-restricted kernel machine. In 2021 International Joint Conference on Neural Networks (IJCNN), pages 1-8. IEEE, 2021.

Laurens Van der Maaten and Geoffrey Hinton. Visualizing data using t-sne. Journal of machine learning research, 9(11), 2008.

Bernhard Schölkopf, Alexander Smola, and Klaus-Robert Müller. Kernel principal component analysis. In International conference on artificial neural networks, pages 583-588. Springer, 1997.

Bernhard Schölkopf, Alexander Smola, and Klaus-Robert Müller. Nonlinear component analysis as a kernel eigenvalue problem. Neural computation, 10(5):1299-1319, 1998.

Ali Rahimi and Benjamin Recht. Random features for large-scale kernel machines. Advances in neural information processing systems, 20, 2007.

Dan Hendrycks, Steven Basart, Mantas Mazeika, Andy Zou, Joseph Kwon, Mohammadreza Mostajabi, Jacob Steinhardt, and Dawn Song. Scaling out-of-distribution detection for realworld settings. In International Conference on Machine Learning, pages 8759-8773. PMLR, 2022.

Dan Hendrycks and Kevin Gimpel. A baseline for detecting misclassified and out-of-distribution examples in neural networks. In International Conference on Learning Representations, 2016.

Shiyu Liang, Yixuan Li, and R Srikant. Enhancing the reliability of out-of-distribution image detection in neural networks. In International Conference on Learning Representations, 2018.

Yingwen Wu, Tao Li, Xinwen Cheng, Jie Yang, and Xiaolin Huang. Low-dimensional gradient helps out-of-distribution detection. IEEE Transactions on Pattern Analysis and Machine Intelligence, 2024.

Yiyou Sun, Chuan Guo, and Yixuan Li. React: Out-of-distribution detection with rectified activations. Advances in Neural Information Processing Systems, 34:144-157, 2021.

Yao Zhu, YueFeng Chen, Chuanlong Xie, Xiaodan Li, Rong Zhang, Hui Xue, Xiang Tian, Yaowu Chen, et al. Boosting out-of-distribution detection with typical features. Advances in Neural Information Processing Systems, 35:20758-20769, 2022.

Andrija Djurisic, Nebojsa Bozanic, Arjun Ashok, and Rosanne Liu. Extremely simple activation shaping for out-of-distribution detection. In The Eleventh International Conference on Learning Representations, 2023.

Kai Xu, Rongyu Chen, Gianni Franchi, and Angela Yao. Scaling for training time and posthoc out-of-distribution detection enhancement. In The Twelfth International Conference on Learning Representations, 2024.

Yue Yuan, Rundong He, Yicong Dong, Zhongyi Han, and Yilong Yin. Discriminability-driven channel selection for out-of-distribution detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 26171-26180, 2024.

Kimin Lee, Kibok Lee, Honglak Lee, and Jinwoo Shin. A simple unified framework for detecting out-of-distribution samples and adversarial attacks. Advances in neural information processing systems, 31, 2018.

Jaewoo Park, Yoon Gyo Jung, and Andrew Beng Jin Teoh. Nearest neighbor guidance for out-of-distribution detection. In Proceedings of the IEEE/CVF International Conference on Computer Vision, pages 1686-1695, 2023.

Yeonguk Yu, Sungho Shin, Seongju Lee, Changhyun Jun, and Kyoobin Lee. Block selection method for using feature norm in out-of-distribution detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 15701-15711, 2023.

Yue Song, Nicu Sebe, and Wei Wang. Rankfeat: Rank-1 feature removal for out-of-distribution detection. Advances in Neural Information Processing Systems, 35:17885-17898, 2022.

Yen-Chang Hsu, Yilin Shen, Hongxia Jin, and Zsolt Kira. Generalized odin: Detecting outof-distribution image without learning from out-of-distribution data. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 10951-10960, 2020.

Zihan Zhang and Xiang Xiang. Decoupling maxlogit for out-of-distribution detection. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 3388-3397, 2023.

Kun Fang, Qinghua Tao, Xiaolin Huang, and Jie Yang. Revisiting deep ensemble for out-ofdistribution detection: A loss landscape perspective. International Journal of Computer Vision, pages 1-20, 2024.

Haotian Ye, Chuanlong Xie, Tianle Cai, Ruichen Li, Zhenguo Li, and Liwei Wang. Towards a theoretical framework of out-of-distribution generalization. Advances in Neural Information Processing Systems, 34:23519-23531, 2021.

Zhen Fang, Yixuan Li, Jie Lu, Jiahua Dong, Bo Han, and Feng Liu. Is out-of-distribution detection learnable? Advances in Neural Information Processing Systems, 35:37199-37213, 2022.

Jihoon Tack, Sangwoo Mo, Jongheon Jeong, and Jinwoo Shin. Csi: Novelty detection via contrastive learning on distributionally shifted instances. Advances in neural information processing systems, 33:11839-11852, 2020.

Vikash Sehwag, Mung Chiang, and Prateek Mittal. Ssd: A unified framework for self-supervised outlier detection. In International Conference on Learning Representations, 2020.

Yiyou Sun and Yixuan Li. Dice: Leveraging sparsification for out-of-distribution detection. In European Conference on Computer Vision, pages 691-708. Springer, 2022.

Haoqi Wang, Zhizhong Li, Litong Feng, and Wayne Zhang. Vim: Out-of-distribution with virtual-logit matching. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 4921-4930, 2022.

Walter Rudin. Fourier analysis on groups, volume 121967. Wiley Online Library, 1962.

Kun Fang, Fanghui Liu, Xiaolin Huang, and Jie Yang. End-to-end kernel learning via generative random fourier features. Pattern Recognition, 134:109057, 2023.

Mikhail Belkin, Daniel Hsu, Siyuan Ma, and Soumik Mandal. Reconciling modern machinelearning practice and the classical bias-variance trade-off. Proceedings of the National Academy of Sciences, 116(32):15849-15854, 2019.

AKrizhevsky. Learning multiple layers of features from tiny images. Master's thesis, University of Toronto, 2009.

Jia Deng, Wei Dong, Richard Socher, Li-Jia Li, Kai Li, and Li Fei-Fei. Imagenet: A large-scale hierarchical image database. In IEEE Conference on Computer Vision and Pattern Recognition, pages 248-255, 2009.

Yuval Netzer, Tao Wang, Adam Coates, Alessandro Bissacco, Bo Wu, and Andrew Y Ng. Reading digits in natural images with unsupervised feature learning. In Proceedings of the NIPS Workshop on Deep Learning and Unsupervised Feature Learning, 2011.

Fisher Yu, Ari Seff, Yinda Zhang, Shuran Song, Thomas Funkhouser, and Jianxiong Xiao. Lsun: Construction of a large-scale image dataset using deep learning with humans in the loop. arXiv preprint arXiv:1506.03365, 2015.

Pingmei Xu, Krista A Ehinger, Yinda Zhang, Adam Finkelstein, Sanjeev R Kulkarni, and Jianxiong Xiao. Turkergaze: Crowdsourcing saliency with webcam based eye tracking. arXiv preprint arXiv:1504.06755, 2015.

Mircea Cimpoi, Subhransu Maji, Iasonas Kokkinos, Sammy Mohamed, and Andrea Vedaldi. Describing textures in the wild. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 3606-3613, 2014.

Bolei Zhou, Agata Lapedriza, Aditya Khosla, Aude Oliva, and Antonio Torralba. Places: A 10 million image database for scene recognition. IEEE transactions on pattern analysis and machine intelligence, 40(6):1452-1464, 2017.

Grant Van Horn, Oisin Mac Aodha, Yang Song, Yin Cui, Chen Sun, Alex Shepard, Hartwig Adam, Pietro Perona, and Serge Belongie. The inaturalist species classification and detection dataset. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 8769-8778, 2018.

Jianxiong Xiao, James Hays, Krista A Ehinger, Aude Oliva, and Antonio Torralba. Sun database: Large-scale scene recognition from abbey to zoo. In 2010 IEEE computer society conference on computer vision and pattern recognition, pages 3485-3492. IEEE, 2010.

Jeff Johnson, Matthijs Douze, and Hervé Jégou. Billion-scale similarity search with gpus. IEEE Transactions on Big Data, 7(3):535-547, 2019.

Prannay Khosla, Piotr Teterwak, Chen Wang, Aaron Sarna, Yonglong Tian, Phillip Isola, Aaron Maschinot, Ce Liu, and Dilip Krishnan. Supervised contrastive learning. Advances in neural information processing systems, 33:18661-18673, 2020.

Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun. Deep residual learning for image recognition. In IEEE Conference on Computer Vision and Pattern Recognition, pages 770-778, 2016.

Mark Sandler, Andrew Howard, Menglong Zhu, Andrey Zhmoginov, and Liang-Chieh Chen. Mobilenetv2: Inverted residuals and linear bottlenecks. In Proceedings of the IEEE conference on computer vision and pattern recognition, pages 4510-4520, 2018.

Adam Paszke, Sam Gross, Francisco Massa, Adam Lerer, James Bradbury, Gregory Chanan, Trevor Killeen, Zeming Lin, Natalia Gimelshein, Luca Antiga, et al. Pytorch: An imperative style, high-performance deep learning library. Advances in neural information processing systems, 32, 2019.

JT-Y Kwok and IW-H Tsang. The pre-image problem in kernel methods. IEEE transactions on neural networks, 15(6):1517-1525, 2004.

Andrew Gordon Wilson, Zhiting Hu, Ruslan Salakhutdinov, and Eric P Xing. Deep kernel learning. In Artificial intelligence and statistics, pages 370-378. PMLR, 2016.

Zhihui Zhu, Tianyu Ding, Jinxin Zhou, Xiao Li, Chong You, Jeremias Sulam, and Qing Qu. A geometric analysis of neural collapse with unconstrained features. Advances in Neural Information Processing Systems, 34:29820-29834, 2021.

Ninh Pham and Rasmus Pagh. Fast and scalable polynomial kernels via explicit feature maps. In Proceedings of the 19th ACM SIGKDD international conference on Knowledge discovery and data mining, pages 239-247, 2013.

Heiko Hoffmann. Kernel pca for novelty detection. Pattern recognition, 40(3):863-874, 2007.

A Details of representative OoD detectors

In this section, we elaborate the scoring function S ( · ) of the OoD detectors included in the comparison experiments of Section 5. Given a well-trained DNN f : R d → R c with inputs x ∈ R d , the outputs are c -dimension logits f ( x ) ∈ R c w.r.t c classes. The DNN f learns features z ∈ R m of x before the last linear layer, i.e. , the penultimate features z .

MSP [15] employs the softmax function on the output logits and takes the maximum probability as the scoring function. Given a new sample ˆ x ∈ R d , its MSP score is

ODIN [16] introduces the temperature scaling and adversarial examples into the MSP score:

where T denotes the temperature and ˆ x a denotes the perturbed adversarial examples of ˆ x .

Mahala [23] employs the Mahalanobis score to perform OoD detection. The DNN outputs at different layers are modeled as a mixture of multivariate Gaussian distributions, and the Mahalanobis distance is calculated. Then, a linear regressor is trained to achieve a weighted Mahalanobis distance at different layers as the final detection score. To train the linear regressor, the training data and the corresponding adversarial examples are adopted as positive and negative samples, respectively.

where f l ( ˆ x ) denotes the output features at the l -th layer with the associated mean feature vector µ l i of classi and the covariance matrix Σ l , and α l denotes the linear regression coefficients.

Energy [5] uses an energy function on logits as energy is well aligned with input probability densities:

where f i ( ˆ x ) denotes the i -th element in the c -dimension output logits f ( ˆ x ) .

GODIN [27] improves ODIN from 2 aspects: decomposing the probabilities and modifying the input pre-processing. On the one hand, a two-branch structure with learnable parameters is imposed after the logits to formulate the decomposed probablities. On the other hand, the magnitude of the adversarial examples is optimized instead of manually tuned in ODIN.

ReAct [18] proposes activation truncation on the penultimate features z of DNNs, as the authors observe that features of OoD data generally hold high unit activations in the penultimate layers. The feature clipping is implemented in a simple way:

where α is a pre-defined constant. The clipped features ¯ z then pass through the last linear layer and yield modified logits. Other logits-based OoD methods such as Energy could be applied on the modified logits to produce a detection score.

KNN [7] is a simple but time-consuming and memory-inefficient detector since it performs nearest neighbor search on the ℓ 2 -normalized penultimate features between the test sample and all the training samples. The negative of the ( k -th) shortest ℓ 2 distance is set as the score for a new sample ˆ x .

ViM [35] combines information from both logits and features in a complicated way for OoD detection. Firstly, penultimate features z are projected to the residual space obtained by PCA. Then the norm of projected features gets scaled together with the logits via the softmax function. Finally the scaled feature norm is selected as the detection score.

DICE [34] is a sparsification-based OoD detector by preserving the most important weights in the last linear layer. Denote the weights W ∈ R m × c and the bias b ∈ R c in the last linear layer, the forward propagation of DICE is defined as:

⊙ is the element-wise multiplication, and M ∈ R m × c is a masking matrix whose elements are determined by the element-wise multiplication between the i -th column w i ∈ R m in W and the penultimate features ˆ z : w i ⊙ ˆ z . Then, similar as ReAct, logits-based detectors could be executed on the modified logits f DICE ( ˆ x ) to produce a detection score.

BATS [19] proposes to truncate the extreme outputs of Batch Normalization (BN) layers via the estimated mean and standard deviations stored in BN layers, as those extreme features would lead to ambiguity and should be rectified. However, in the released code, the authors actually does not use any information from the BN layers, but instead simply perform clipping on the penultimate features z via the feature mean and standard deviations.

PCA [8] re-formulates the reconstruction errors and empirically shows the inseparativity via the re-formulated errors between InD and OoD data in the primal z -space. The authors further propose a regularized reconstruction error and a fusion strategy to boost the OoD detection performance.

NNGuide [24] exploits the guidance of the Energy score on logits to boost the detection performance of the nearest neighbor search on features. Specifically, the training features are firstly scaled by their corresponding Energy scores, then KNN is executed on such re-scaled features for the new sample. The final detection score is set as the multiplication of the searched distance and the Energy score. The time and memory complexity of NNGuide is still the same O ( N tr ) as that of KNN [7].

DML [28] decouples the maximum logits into two parts: the maximum cosine similarity (MaxCosine) and the maximum norm (MaxNorm), and employs their ensemble as the detection score. DML reveals that the cosine similarity and the feature norm jointly contribute to the effectiveness of the previous MSP [15] and MaxLogit [14] methods and designs new training losses from the perspective of feature collapse [55], so as to further improve the performance of MaxCosine and MaxNorm.

ASH [20] is a post-hoc detection method that removes the abnormal information in features. ASH includes two stages: removing a large portion of the features, and adjusting the remaining feature values by scaling up or assigning a constant value. ASH exhibits advantages over the classic ReAct method [18]: no global thresholds and stronger flexibility, and shows better detection performance.

SCALE [21] analyzes the rectification and scaling components of the ASH method, and improves ASH by only a scaling process in the post-hoc stage.

DDCS [22] investigates the effects of different channels based on existing feature-clipping detection methods, and proposes a channel-level anomalous activations pre-rectifying module so as to clip features more carefully for better detection performance.

We follow the settings in KNN [7] and include CSI [32] and SSD [33] into the comparisons in Section 5.1. The 2 methods adopt the contrastive losses to train DNNs. In the comparison results of Table 1 and the following Table 4, the reported detection results of CSI and SSD are directly from [7], and are obtained by executing the Mahalanobis detector on learned features of DNNs trained by CSI and SSD. Refer to [7] for more details.

B Supplementary experiment results on OoD detection

Table 4 illustrates the comparison results on the CIFAR10 benchmark between our CoP/CoRP and the KNN detector [7]. Similar as the comparisons on the ImageNet-1K benchmark in Table 1, CoRP outperforms other baselines in both the standard training and the supervised contrastive learning with lower FPR and higher AUROC average values.

Table 5 shows the comparison results on the ImageNet-1K benchmark between our CoP/CoRP and the regularized reconstruction error [8] of MobileNet [51]. Similar as the case of ResNet50 in Table 3, under the same fusion trick with other detection scores, our KPCA reconstruction errors of CoP and CoRP significantly outperform the regularized PCA reconstruction error of [8], implying the substantial improvements by characterizing the non-linear data distribution of the InD and OoD features via the devised two proper non-linear kernels.

C Analytical discussions on kernels

In this section, more in-depth discussions are drawn on the effects of cosine and Gaussian kernels in CoP and CoRP for OoD detection in Appendix C.1 and Appendix C.2, respectively. A comprehensive sensitivity analysis on the involved hyper-parameters in CoP and CoRP are presented in Appendix C.3.

C.1 Effects of the cosine kernel

The cosine kernel in CoP and CoRP appears an indispensable basis in alleviating the linear inseparability in InD and OoD features. The reason for its effectiveness lies in the imbalanced feature norms ∥ z ∥ 2 between InD and OoD features, which has also been observed in preceding works [7, 6, 32]. Figure 3 shows the feature norms of multiple InD and OoD data sets, from which one can find clear disparities of the InD and OoD feature norms. The cosine kernel k cos and the corresponding feature

4

6

8

10

12

CIFAR10

LSUN

places365

20

30

40

50

ImageNet-1K

SUN

Textures

InD (CIFAR10)

OoD (LSUN)

OoD (iSUN)

mapping ϕ cos in Equation (6) thereby normalize the feature norms and facilitate the separability between InD and OoD data.

Figure 4 illustrates the t-SNE visualization on the InD and OoD features to further imply the importance of the cosine kernel. As shown in the middle panel of Figure 4, the Gaussian kernel alone fails in creating separable InD and OoD features in the mapped space and actually leads to a complete mess of the mapped features. In contrast, the cosine kernel significantly alleviates the linearly-inseparability of features, shown in the right panel of Figure 4.

Ablation studies on the cosine feature mapping ϕ cos in CoP and CoRP are executed to verify its indispensability for OoD detection. Specifically, CoP without ϕ cos reduces to a standard PCA on the z -space, and CoRP without ϕ cos reduces to KPCA with a Gaussian kernel. Table 6 shows the corresponding detection FPR and AUROC values on each OoD data set in the ImageNet-1K benchmark of ablations on ϕ cos . Both the standard PCA and the Gaussian KPCA exhibit worse detection performance than CoP and CoRP. Particularly, the single Gaussian kernel in KPCA actually results in a complete failure in detecting OoD samples with nearly 95% FPR values. Therefore, the cosine kernel is essential in characterizing the non-linearity in InD and OoD features and critical for the superior performance of the KPCA detector.

C.2 Alternative kernels

The design of the Gaussian kernel in CoRP is motivated by the useful ℓ 2 distance on z ∥ z ∥ 2 in the KNN detector [7]. The Gaussian kernel preserves the beneficial ℓ 2 distance relationship in ϕ cos ( z ) -space through the RFFs mapping. In this section, we provide two alternative choices aside from the cosine-Gaussian kernel.

The cosine-Laplacian kernel explores the ℓ 1 distance in ϕ cos ( z ) -space via the Laplacian kernel k lap :

To construct the RFFs for k lap , the sampling distribution of the ω i in Equation (4) is a Cauchy distribution ω ∼ p ( ω ) = γ 2 πγ ( ω 2 + γ 2 ) .

The cosine-polynomial kernel does not hold the ℓ 1 nor ℓ 2 distance-preserving property for ϕ cos ( z ) -space, as the polynomial kernel is defined as:

To obtain an explicit feature mapping for k poly , we do not adopt the RFFs and take the Tensor Sketch approximation [56] instead for simplicity.

Table 6 illustrates the comparisons on the detection performance among multiple alternative kernels. Actually, both the cosine-Laplacian kernel and the cosine-polynomial kernel cannot bring detection performance gains on top of the cosine kernel (CoP), which indicates that the ℓ 1 -distance relationship characterized by the Laplacian kernel and the inner-product information characterized by the polynomial kernel in the ϕ cos ( z ) -space are less effective in promoting the separability between InD and OoD features. Thus, the cosine-Gaussian kernel is used and recommended in the proposed KPCA method for OoD detection.

C.3 Sensitivity analysis

A comprehensive sensitivity analysis is executed to show the effects of hyper-parameters in CoP and CoRP. A common hyper-parameter in CoP and CoRP is the number of columns q of the dimensionality-reduction matrix U Φ q . Additional hyper-parameters of CoRP include the bandwidth γ of the Gaussian kernel and the number of RFFs M . In the following, we discuss the influence of each hyper-parameter, and report experiment results of the detection performance by varying one hyper-parameter with the others fixed.

Effect of q q indicates the number of preserved principal components and determines how much information captured by the subspace where the InD and OoD data is projected onto. q is selected as the minimal number of principal components with the amount of information that exceeds the given explained variance ratio.

Figure 5 illustrates the detection performance of CoP and CoRP under varied explained variance ratios. On CIFAR10 and ImageNet-1K benchmarks, for CoP, a mild value of the explained variance ratio is suggested with around 90% for keeping the components. Regarding CoRP, a sufficiently large value of the explained variance ratio is no longer essential for CoRP on the ImageNet-1K benchmark, which might be due to that the 2 concatenated kernels make the useful information for distinguishing OoD samples more concentrated in less principal components.

̸

Effect of γ The Gaussian kernel width γ directly affects the mapped data distribution. For a large γ , k gau ( z 1 , z 2 ) = e -γ ∥ z 1 -z 2 ∥ 2 2 ≈ 0 for z 1 = z 2 , which indicates that the mapped features of z 1 and z 2 are (nearly) mutually-orthogonal. In this case, a PCA would become meaningless. For a small γ , the KPCA-based reconstruction errors will approach the standard PCA-based ones, shown by [57]. Figure 6 illustrates the detection FPR95 and AUROC values of CoRP w.r.t varied Gaussian kernel width γ on CIFAR10 and ImageNet-1K benchmarks. Clearly, neither a too large nor a too small kernel width benefits the detection performance, and a mild value of γ should be carefully tuned for different in-distribution data.

Effect of M The number of RFFs M determines the approximation ability of RFFs towards the Gaussian kernel. As proved in [13], the larger the M , the better the RFFs approximate k gau .

0.5

0.6

0.7

0.8

0.9

1.0

explained variance ratio

10

30

50

70

90

FPR95 (%)

CIFAR10, CoP

FPR95

AUROC

0.90

0.92

0.94

0.96

0.98

1.00

explained variance ratio

50

55

60

65

70

FPR95 (%)

ImageNet-1K, CoP

55

65

75

85

95

AUROC (%)

70

75

80

85

90

AUROC (%)

0.5

0.6

0.7

0.8

0.9

1.0

explained variance ratio

25

35

45

FPR95 (%)

CIFAR10, CoRP

FPR95

AUROC

0.3

0.4

0.5

0.6

0.7

0.8

explained variance ratio

46

50

54

FPR95 (%)

ImageNet-1K, CoRP

85

90

95

AUROC (%)

80

84

88

AUROC (%)

0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0

Gaussian kernel width

25

35

45

FPR95 (%)

CIFAR10, CoRP

FPR95

AUROC

0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0

Gaussian kernel width

45

55

65

75

FPR95 (%)

ImageNet-1K, CoRP

85

90

95

AUROC (%)

70

75

80

85

AUROC (%)

Figure 7 indicates the detection FPR95 and AUROC values of CoRP w.r.t. multiple values of the RFFs dimension M on CIFAR10 and ImageNet-1K benchmarks. As M increases, the detection performance gets improved since the RFFs better converge to the Gaussian kernel. Considering the computation efficiency of eigendecomposition on the covariance matrix of R M × M , in the comparison experiments, we adopt M = 4 m on CIFAR10 with m = 512 for ResNet18, and M = 2 m on ImageNet-1K with m = 2048 for ResNet50 and m = 1280 for MobileNet.

D Supplementary theoretical results

The proof of Proposition 1 is presented.

Proof. Recall z ∈ R m and suppose Φ : R m → R M and U Φ ∈ R M × M is the eigenvector matrix of the covariance matrix of the training data with U Φ = [ U Φ q , U Φ p ] and q + p = M . For the reconstruction error e Φ ( ˆ z ) of a new test sample ˆ z ∈ R m in the mapped Φ( z ) -space, we have:

512

1024

1536

2048

dimension

M

of RFFs

25

35

45

FPR95 (%)

CIFAR10, CoRP

FPR95

AUROC

5121024

2048

4096

dimension

M

of RFFs

45

55

65

75

FPR95 (%)

ImageNet-1K, CoRP

92

93

94

95

AUROC (%)

70

75

80

85

AUROC (%)

The key in the proof of Proposition 1 is U Φ q U Φ ⊤ q + U Φ p U Φ ⊤ p = I . Since U Φ is the eigenvector matrix of the covariance matrix, thereby U Φ is a unitary matrix and satisfies U Φ U Φ ⊤ = U Φ ⊤ U Φ = I , which leads to U Φ q U Φ ⊤ q + U Φ p U Φ ⊤ p = I .

NeurIPS Paper Checklist

1. Claims

Question: Do the main claims made in the abstract and introduction accurately reflect the paper's contributions and scope?

Answer: [Yes]

Justification: We have made clear claims on the paper's contributions and scope in the abstract and introduction.

Guidelines:

The answer NA means that the abstract and introduction do not include the claims made in the paper.

The abstract and/or introduction should clearly state the claims made, including the contributions made in the paper and important assumptions and limitations. A No or NA answer to this question will not be perceived well by the reviewers.

The claims made should match theoretical and experimental results, and reflect how much the results can be expected to generalize to other settings.

It is fine to include aspirational goals as motivation as long as it is clear that these goals are not attained by the paper.

2. Limitations

Question: Does the paper discuss the limitations of the work performed by the authors?

Answer: [Yes]

Justification: We have discussed the limitations of this work in Section 7.

Guidelines:

The answer NA means that the paper has no limitation while the answer No means that the paper has limitations, but those are not discussed in the paper.

The authors are encouraged to create a separate "Limitations" section in their paper.

The paper should point out any strong assumptions and how robust the results are to violations of these assumptions (e.g., independence assumptions, noiseless settings, model well-specification, asymptotic approximations only holding locally). The authors should reflect on how these assumptions might be violated in practice and what the implications would be.

The authors should reflect on the scope of the claims made, e.g., if the approach was only tested on a few datasets or with a few runs. In general, empirical results often depend on implicit assumptions, which should be articulated.

The authors should reflect on the factors that influence the performance of the approach. For example, a facial recognition algorithm may perform poorly when image resolution is low or images are taken in low lighting. Or a speech-to-text system might not be used reliably to provide closed captions for online lectures because it fails to handle technical jargon.

The authors should discuss the computational efficiency of the proposed algorithms and how they scale with dataset size.

If applicable, the authors should discuss possible limitations of their approach to address problems of privacy and fairness.

While the authors might fear that complete honesty about limitations might be used by reviewers as grounds for rejection, a worse outcome might be that reviewers discover limitations that aren't acknowledged in the paper. The authors should use their best judgment and recognize that individual actions in favor of transparency play an important role in developing norms that preserve the integrity of the community. Reviewers will be specifically instructed to not penalize honesty concerning limitations.

3. Theory Assumptions and Proofs

Question: For each theoretical result, does the paper provide the full set of assumptions and a complete (and correct) proof?

Answer: [Yes]

Justification: The paper provide the full set of assumptions and a complete and correct proof for each theoretical result.

Guidelines:

The answer NA means that the paper does not include theoretical results.

All the theorems, formulas, and proofs in the paper should be numbered and crossreferenced.

All assumptions should be clearly stated or referenced in the statement of any theorems.

The proofs can either appear in the main paper or the supplemental material, but if they appear in the supplemental material, the authors are encouraged to provide a short proof sketch to provide intuition.

Inversely, any informal proof provided in the core of the paper should be complemented by formal proofs provided in appendix or supplemental material.

Theorems and Lemmas that the proof relies upon should be properly referenced.

4. Experimental Result Reproducibility

Question: Does the paper fully disclose all the information needed to reproduce the main experimental results of the paper to the extent that it affects the main claims and/or conclusions of the paper (regardless of whether the code and data are provided or not)?

Answer: [Yes]

Justification: We have fully disclosed all the information needed to reproduce the main experimental results in the appendix and submitted anonymous code for the reproduction.

Guidelines:

The answer NA means that the paper does not include experiments.

If the paper includes experiments, a No answer to this question will not be perceived well by the reviewers: Making the paper reproducible is important, regardless of whether the code and data are provided or not.

If the contribution is a dataset and/or model, the authors should describe the steps taken to make their results reproducible or verifiable.

Depending on the contribution, reproducibility can be accomplished in various ways. For example, if the contribution is a novel architecture, describing the architecture fully might suffice, or if the contribution is a specific model and empirical evaluation, it may be necessary to either make it possible for others to replicate the model with the same dataset, or provide access to the model. In general. releasing code and data is often one good way to accomplish this, but reproducibility can also be provided via detailed instructions for how to replicate the results, access to a hosted model (e.g., in the case of a large language model), releasing of a model checkpoint, or other means that are appropriate to the research performed.

While NeurIPS does not require releasing code, the conference does require all submissions to provide some reasonable avenue for reproducibility, which may depend on the nature of the contribution. For example

(a) If the contribution is primarily a new algorithm, the paper should make it clear how to reproduce that algorithm.

(b) If the contribution is primarily a new model architecture, the paper should describe the architecture clearly and fully.

(c) If the contribution is a new model (e.g., a large language model), then there should either be a way to access this model for reproducing the results or a way to reproduce the model (e.g., with an open-source dataset or instructions for how to construct the dataset).

(d) We recognize that reproducibility may be tricky in some cases, in which case authors are welcome to describe the particular way they provide for reproducibility. In the case of closed-source models, it may be that access to the model is limited in some way (e.g., to registered users), but it should be possible for other researchers to have some path to reproducing or verifying the results.

5. Open access to data and code

Question: Does the paper provide open access to the data and code, with sufficient instructions to faithfully reproduce the main experimental results, as described in supplemental material?

Answer: [Yes]

Justification: We have submitted anonymous code for the reproduction of the proposed algorithm in this work. The adopted data is public.

Guidelines:

The answer NA means that paper does not include experiments requiring code.

Please see the NeurIPS code and data submission guidelines ( https://nips.cc/ public/guides/CodeSubmissionPolicy ) for more details.

While we encourage the release of code and data, we understand that this might not be possible, so 'No' is an acceptable answer. Papers cannot be rejected simply for not including code, unless this is central to the contribution (e.g., for a new open-source benchmark).

The instructions should contain the exact command and environment needed to run to reproduce the results. See the NeurIPS code and data submission guidelines ( https: //nips.cc/public/guides/CodeSubmissionPolicy ) for more details.

The authors should provide instructions on data access and preparation, including how to access the raw data, preprocessed data, intermediate data, and generated data, etc.

The authors should provide scripts to reproduce all experimental results for the new proposed method and baselines. If only a subset of experiments are reproducible, they should state which ones are omitted from the script and why.

At submission time, to preserve anonymity, the authors should release anonymized versions (if applicable).

Providing as much information as possible in supplemental material (appended to the paper) is recommended, but including URLs to data and code is permitted.

6. Experimental Setting/Details

Question: Does the paper specify all the training and test details (e.g., data splits, hyperparameters, how they were chosen, type of optimizer, etc.) necessary to understand the results?

Answer: [Yes]

Justification: All the experiment details have been specified in both the appendix and the released anonymous code.

Guidelines:

The answer NA means that the paper does not include experiments.

The experimental setting should be presented in the core of the paper to a level of detail that is necessary to appreciate the results and make sense of them.

The full details can be provided either with the code, in appendix, or as supplemental material.

7. Experiment Statistical Significance

Question: Does the paper report error bars suitably and correctly defined or other appropriate information about the statistical significance of the experiments?

Answer: [No]

Justification: The involved DNNs are pre-trained and the results of the PCA operation are deterministic.

Guidelines:

The answer NA means that the paper does not include experiments.

The authors should answer "Yes" if the results are accompanied by error bars, confidence intervals, or statistical significance tests, at least for the experiments that support the main claims of the paper.

The factors of variability that the error bars are capturing should be clearly stated (for example, train/test split, initialization, random drawing of some parameter, or overall run with given experimental conditions).

The method for calculating the error bars should be explained (closed form formula, call to a library function, bootstrap, etc.)

The assumptions made should be given (e.g., Normally distributed errors).

It should be clear whether the error bar is the standard deviation or the standard error of the mean.

It is OK to report 1-sigma error bars, but one should state it. The authors should preferably report a 2-sigma error bar than state that they have a 96% CI, if the hypothesis of Normality of errors is not verified.

For asymmetric distributions, the authors should be careful not to show in tables or figures symmetric error bars that would yield results that are out of range (e.g. negative error rates).

If error bars are reported in tables or plots, The authors should explain in the text how they were calculated and reference the corresponding figures or tables in the text.

8. Experiments Compute Resources

Question: For each experiment, does the paper provide sufficient information on the computer resources (type of compute workers, memory, time of execution) needed to reproduce the experiments?

Answer: [Yes]

Justification: We have provided sufficient information on the computer resources.

Guidelines:

The answer NA means that the paper does not include experiments.

The paper should indicate the type of compute workers CPU or GPU, internal cluster, or cloud provider, including relevant memory and storage.

The paper should provide the amount of compute required for each of the individual experimental runs as well as estimate the total compute.

The paper should disclose whether the full research project required more compute than the experiments reported in the paper (e.g., preliminary or failed experiments that didn't make it into the paper).

9. Code Of Ethics

Question: Does the research conducted in the paper conform, in every respect, with the NeurIPS Code of Ethics https://neurips.cc/public/EthicsGuidelines ?

Answer: [Yes]

Justification: The research in the paper conforms with the NeurIPS Code of Ethics in every aspect.

Guidelines:

The answer NA means that the authors have not reviewed the NeurIPS Code of Ethics.

If the authors answer No, they should explain the special circumstances that require a deviation from the Code of Ethics.

The authors should make sure to preserve anonymity (e.g., if there is a special consideration due to laws or regulations in their jurisdiction).

10. Broader Impacts

Question: Does the paper discuss both potential positive societal impacts and negative societal impacts of the work performed?

Answer: [Yes]

Justification: We have discussed the societal impacts of the work in Section 7.

Guidelines:

The answer NA means that there is no societal impact of the work performed.

If the authors answer NA or No, they should explain why their work has no societal impact or why the paper does not address societal impact.

Examples of negative societal impacts include potential malicious or unintended uses (e.g., disinformation, generating fake profiles, surveillance), fairness considerations (e.g., deployment of technologies that could make decisions that unfairly impact specific groups), privacy considerations, and security considerations.

The conference expects that many papers will be foundational research and not tied to particular applications, let alone deployments. However, if there is a direct path to any negative applications, the authors should point it out. For example, it is legitimate to point out that an improvement in the quality of generative models could be used to generate deepfakes for disinformation. On the other hand, it is not needed to point out that a generic algorithm for optimizing neural networks could enable people to train models that generate Deepfakes faster.

The authors should consider possible harms that could arise when the technology is being used as intended and functioning correctly, harms that could arise when the technology is being used as intended but gives incorrect results, and harms following from (intentional or unintentional) misuse of the technology.

If there are negative societal impacts, the authors could also discuss possible mitigation strategies (e.g., gated release of models, providing defenses in addition to attacks, mechanisms for monitoring misuse, mechanisms to monitor how a system learns from feedback over time, improving the efficiency and accessibility of ML).

11. Safeguards

Question: Does the paper describe safeguards that have been put in place for responsible release of data or models that have a high risk for misuse (e.g., pretrained language models, image generators, or scraped datasets)?

Answer: [NA]

Justification: No new models nor datasets are released in this work, and thus the paper poses no such risks.

Guidelines:

The answer NA means that the paper poses no such risks.

Released models that have a high risk for misuse or dual-use should be released with necessary safeguards to allow for controlled use of the model, for example by requiring that users adhere to usage guidelines or restrictions to access the model or implementing safety filters.

Datasets that have been scraped from the Internet could pose safety risks. The authors should describe how they avoided releasing unsafe images.

We recognize that providing effective safeguards is challenging, and many papers do not require this, but we encourage authors to take this into account and make a best faith effort.

12. Licenses for existing assets

Question: Are the creators or original owners of assets (e.g., code, data, models), used in the paper, properly credited and are the license and terms of use explicitly mentioned and properly respected?

Answer: [Yes]

Justification: All the creators and original owners of assets used in the paper have been properly credited. The license and terms of use have been explicitly mentioned and properly respected.

Guidelines:

The answer NA means that the paper does not use existing assets.

The authors should cite the original paper that produced the code package or dataset.

The authors should state which version of the asset is used and, if possible, include a URL.

The name of the license (e.g., CC-BY 4.0) should be included for each asset.

For scraped data from a particular source (e.g., website), the copyright and terms of service of that source should be provided.

If assets are released, the license, copyright information, and terms of use in the package should be provided. For popular datasets, paperswithcode.com/datasets has curated licenses for some datasets. Their licensing guide can help determine the license of a dataset.

For existing datasets that are re-packaged, both the original license and the license of the derived asset (if it has changed) should be provided.

If this information is not available online, the authors are encouraged to reach out to the asset's creators.

13. New Assets

Question: Are new assets introduced in the paper well documented and is the documentation provided alongside the assets?

Answer: [Yes]

Justification: New asserts introduced in the paper have been well documented and provided. Guidelines:

The answer NA means that the paper does not release new assets.

Researchers should communicate the details of the dataset/code/model as part of their submissions via structured templates. This includes details about training, license, limitations, etc.

The paper should discuss whether and how consent was obtained from people whose asset is used.

At submission time, remember to anonymize your assets (if applicable). You can either create an anonymized URL or include an anonymized zip file.

14. Crowdsourcing and Research with Human Subjects

Question: For crowdsourcing experiments and research with human subjects, does the paper include the full text of instructions given to participants and screenshots, if applicable, as well as details about compensation (if any)?

Answer: [NA]

Justification: The paper does not involve crowdsourcing nor research with human subjects.

Guidelines:

The answer NA means that the paper does not involve crowdsourcing nor research with human subjects.

Including this information in the supplemental material is fine, but if the main contribution of the paper involves human subjects, then as much detail as possible should be included in the main paper.

According to the NeurIPS Code of Ethics, workers involved in data collection, curation, or other labor should be paid at least the minimum wage in the country of the data collector.

15. Institutional Review Board (IRB) Approvals or Equivalent for Research with Human Subjects

Question: Does the paper describe potential risks incurred by study participants, whether such risks were disclosed to the subjects, and whether Institutional Review Board (IRB) approvals (or an equivalent approval/review based on the requirements of your country or institution) were obtained?

Answer: [NA]

Justification: The paper does not involve crowdsourcing nor research with human subjects. Guidelines:

The answer NA means that the paper does not involve crowdsourcing nor research with human subjects.

Depending on the country in which research is conducted, IRB approval (or equivalent) may be required for any human subjects research. If you obtained IRB approval, you should clearly state this in the paper.

We recognize that the procedures for this may vary significantly between institutions and locations, and we expect authors to adhere to the NeurIPS Code of Ethics and the guidelines for their institution.

For initial submissions, do not include any information that would break anonymity (if applicable), such as the institution conducting the review.

Peer reviews:
{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThe paper describes a method for out-of-distribution (OOD) detection. Kernel PCA is applied to the penultimate features of a neural network. Two kernels are chosen motivated by prior work on nearest-neighbour-based detection. Namely the cosine kernel and a cosine-Gaussian kernel. In experiments, both methods outperform baseline methods on image-based OOD detection.\n\nSTRENGTHS:\n- The paper is well-written and easy to follow. The work is put into context, clearly motivated and the methods are explained clearly.\n- The method itself is fairly simple and works well which is highly appreciated.\n- Extensive experiments and comparisons with prior work are conducted to showcase the method's performance.\n\nWEAKNESSES:\n- in section 2 it is not entirely clear whether the RFF approximation is used for the the cosine-Gaussian kernel alone or also for the cosine kernel. Also please, elaborate on the details of how the kernel is approximated. \n\n- in relation to the last point, in the experiments, it is important to highlight the dimensionality of the penultimate layer features $c$ and the number of random Fourier features that you select. It is known that for medium to high-dimensional problems, the approximation with RFF requires a very high number of features.\n\n- line 198: the computational complexity of the RFF is not discussed in this paragraph.\n\n- section 2.2 is less related work and more background. Thus, sections 2.2 and 3.1 could be better summarized in a \"background\" section. \n\n- It is not entirely clear how Proposition 2 is necessary to implement CoP and CoRP. Please clarify this in the manuscript.\n\n- at the start of the paper it is unclear why you two kernels (lines 65, 68, ...). Only from the experiments and algorithm 1, it becomes clear that these are two different choices/methods.\n\nQUESTIONS:\n- it is unclear how the proposed methods achieve O(1) time and memory complexity with RFF. Please elaborate on this.\n- line 133: how is $q$ chosen?\n- in Figure 2, please clarify what the kernel function in this experiment exactly is.\n\nSmaller things:\n- line 282: here the standard solution from [1] should be mentioned\n- line 192: wrap up\n- line 259: \"under the same framework\" unclear phrasing\n- line 299: \"we adopt\" remove \"should\"\n- for automatic learning of features from data, a suggestion is to consider Recursive Feature Machines [2].\n\nReferences:\n[1] G. H. Bakır, J. Weston, and B. Schölkopf, “Learning to find pre-images,” in Proc. Adv. Neural Inf. Process. Syst., 2004, pp. 449–456.\n\n[2] A. Radhakrishnan et al., Mechanism for feature learning in neural networks and backpropagation-free machine learning models. Science 383, 1461-1467 (2024).\n\nLIMITATIONS:\nFor reproducibility the main limitation lies in the missing information about the RFF implementation as no information is provided about the number of random Fourier features. Furthermore, it is not clear what other kernel hyperparameters are to be tuned and how they are selected.", "TITLE": "Official Review", "RECOMMENDATION": 6, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2024-07-08"}

comments: SUMMARY:
The paper everage 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 within an O(1) time and memory complexity in inference.

STRENGTHS:
1. The paper is written well and is easy to understand.

2. The studied problem is very important.

3. The results seem to outperform state-of-the-art.

WEAKNESSES:
1. It might be more useful to include more effective post-hoc OOD detection methods, such as ReAct, ASH for comparison. Also, the training-based approach might be useful to be included.

2. It might be more useful to include the ablation results on more kernel designs. 

3. I am wondering why linear separable space between ID and OOD matters, if we have a non-linear classifier, it can still perform accurate OOD detection. 

4. What are some important assumptions here for the theory? Might be useful to provide some justifications if there are any.

QUESTIONS:
see above

LIMITATIONS:
n/a
TITLE: Official Review
SOUNDNESS_CORRECTNESS: 3
DATE: 2024-07-09

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nThe paper introduces a method that applies Kernel Principal Component Analysis (KPCA) to the output of the penultimate layer of a Deep Neural Network (DNN) for out-of-distribution (OOD) detection. Inspired by previous approaches in OOD detection that utilize K-nearest neighbors (KNN) on $\\ell_{2}$ normalized features, two kernels are designed to incorporate these features. The study explores the effectiveness of these kernels and discusses experimental results.\n\nSTRENGTHS:\n1. The paper is well-written and easy to follow.\n\n2. The problem of OOD detection is important in ML and relevant to the Neurips community. \n\n3. Many experiments are conducted and some are promising. For instance, the proposed approach using the Cosine kernel and Gaussian-Cosine kernel performs better than KNN work [1] which the method is inspired.\n\nWEAKNESSES:\n1. It is not clear how the proposed method can adapt to a wider variety of feature maps and effectively leverage corresponding kernels. The current feature map used in this study draws inspiration from [1] and closely resembles it and the main observation of the paper is to consider to corresponding kernel to it. As a result, the effectiveness and novelty of the kernel method in this context are not entirely clear and need to be clarified. \n\n2. The authors mention ‘kernel learning’ as a potential area for future exploration under the study's limitations. However, pursuing kernel learning in this context may appear redundant given the extensive training already performed on the DNN from scratch for the OOD detection task.\n\n[1]Yiyou Sun, Yifei Ming, Xiaojin Zhu, and Yixuan Li. Out-of-distribution detection with deep 358 nearest neighbors. In International Conference on Machine Learning, pages 20827–20840. 359 PMLR, 2022.\n\nQUESTIONS:\n1. How can one select a kernel for OOD detection beyond those discussed in this work? Please refer to my previous comment as well.\n\n2. Could you provide a mathematical justification for why KPCA with a Gaussian cosine kernel or a cosine kernel itself performs better than the KNN method with $\\ell_{2}$ normalization, as discussed in [1]?\n\n[1]Yiyou Sun, Yifei Ming, Xiaojin Zhu, and Yixuan Li. Out-of-distribution detection with deep 358 nearest neighbors. In International Conference on Machine Learning, pages 20827–20840. 359 PMLR, 2022.\n\nLIMITATIONS:\nThe authors discussed the limitations of their work.", "TITLE": "Official Review", "RECOMMENDATION": 5, "REVIEWER_CONFIDENCE": 4, "SOUNDNESS_CORRECTNESS": 3, "DATE": "2024-07-12"}

{"IS_META_REVIEW": false, "comments": "SUMMARY:\nIn this work, the authors leverage the framework of Kernel Principal Component Analysis (KPCA)\nfor Out-of-Distribution (OoD) detection, aiming to enhance the separability between In-Distribution\n(InD) and OoD data within the subspace defined by the principal components. The study introduces\ntwo task-specific kernels: a cosine kernel and a cosine-Gaussian kernel, both meticulously designed\nfor OoD detection. To address the computational challenges associated with large-scale kernel\nmachines, the authors employ Random Fourier Features (RFFs) to approximate the Gaussian kernel\nfunctions. This approach not only maintains the effectiveness of the kernel methods but also\npotentially reduces the time complexity of KPCA detectors, making them more feasible for practical\napplications.\n\nSTRENGTHS:\n- Innovative Kernel Perspective on Existing KNN Detector: The authors creatively take a kernel perspective on an existing k-nearest neighbor (KNN) detector. This novel approach opens new avenues for improving OoD detection performance by leveraging advanced kernel methods.\n- Introduction of Cosine and Cosine-Gaussian Kernels: The proposal of a cosine kernel and a\ncosine-Gaussian kernel for Kernel Principal Component Analysis (KPCA) is a significant\ncontribution. These kernels provide alternative ways to capture non-linear patterns in the data,\nenhancing the effectiveness of the OoD detection process.\n- Utilization of Explicit Feature Mappings: The paper leverages two explicit feature mappings $\\Phi(\\cdot)$ induced from the proposed kernels on the original features $z$. This methodical approach showcases the practical application of kernel methods in transforming the feature space for improved detection accuracy.\n- Well-Written and Insightful: The paper is well-written, clearly presenting complex concepts and\nmethodologies. It provides valuable insights into the application of kernel methods for OoD\ndetection.\n\nWEAKNESSES:\n- **Lack of Evidence Against PCA Method:** There is insufficient evidence to substantiate the claim that the failure of the Principal Component Analysis (PCA) method in OOD detection is due to its reliance on linear mapping. Additional experiments and analyses are necessary to support this assertion.\n- **Outdated Baselines in OOD Detection:** While the experiments on ImageNet-1K show that the proposed Kernel Principal Component Analysis (KPCA) method, which explores non-linear patterns, is advantageous compared to nearest neighbor searching, it remains uncompetitive within the broader out-of-distribution (OOD) detection community. The baselines used for comparison are outdated, undermining the reliability and relevance of the results.\n- **Insufficient Demonstration of $\\ell$2-Normalization Significance:** The demonstration of the indispensable significance of $\\ell$2-normalization is inadequate. More thorough evidence and experiments are required to convincingly establish its critical role in the proposed methodology.\n- **Manual Selection of Kernels and Parameter Tuning**: The specific kernels employed in the study are manually selected and require carefully-tuned parameters. This manual selection process raises concerns about the generalizability and robustness of the proposed method, as it may not perform optimally across diverse datasets and conditions without significant manual intervention.\n\nQUESTIONS:\n- **Evidence Against PCA Method:** The paper mentions the failure of PCA in OoD detection due to its linear mapping. Can you provide more detailed evidence or experiments that explicitly show this limitation of PCA?\n- **Extended Experimental Analysis:** Conduct a more comprehensive experimental analysis, including comparisons with the latest state-of-the-art methods in OoD detection. This will help validate the effectiveness and competitiveness of your proposed method in the context of recent advancements in the field.\n\nLIMITATIONS:\n- Manual Selection of Kernels and Parameters: One significant limitation of the proposed method is the manual selection and careful tuning of the cosine and cosine-Gaussian kernels. This process may not generalize well across different datasets and requires extensive manual intervention, which can be time-consuming and prone to human bias.\n- Comparative Analysis with Outdated Baselines: The study compares the proposed KPCA-based method with outdated OoD detection baselines. This limits the assessment of the method's competitiveness and effectiveness in the context of recent advancements in the field. Including comparisons with the latest state-of-the-art methods would provide a more accurate evaluation.\n\n---------------------------------------------------------------------------------------\nAfter Rebuttal\n\nThe author's detailed response has addressed most of my concerns. I have increased my score. However, I cannot concur with certain aspects, particularly the selection of the kernel and hyperparameter tuning. The FPR cannot serve as a tuning target during training because the OOD datasets are test data. In the setup of this study, only ID data are available for kernel selection and hyperparameter tuning.", "TITLE": "Official Review", "RECOMMENDATION": 5, "REVIEWER_CONFIDENCE": 3, "SOUNDNESS_CORRECTNESS": 2, "DATE": "2024-07-15"}