Detecting Adversarial Examples

## Abstract

Abstract Deep Neural Networks (DNNs) have been shown to be vulnerable to adversarial examples. While numerous successful adversarial attacks have been proposed, defenses against these attacks remain relatively understudied. Existing defense approaches either focus on negating the effects of perturbations caused by the attacks to restore the DNNs’ original predictions or use a secondary model to detect adversarial examples. However, these methods often become ineffective due to the continuous advancements in attack techniques. We propose a novel universal and lightweight method to detect adversarial examples by analyzing the layer outputs of DNNs. Through theoretical justification and extensive experiments, we demonstrate that our detection method is highly effective, compatible with any DNN architecture, and applicable across different domains, such as image, video, and audio.

## 1 Introduction

Goodfellow et al. () demonstrated that deep neural networks (DNNs) are vulnerable to adversarial examples and proposed the Fast Gradient Sign Method (FGSM) to craft these adversarial examples by adding perturbations to the model inputs, leveraging the linear nature of DNNs. After the initial introduction of FGSM, various adversarial attacks were proposed across different domains. However, compared to the vast diversity among attack techniques, existing defense methods are built on a few different strategies.

The most commonly used defense strategy is trying to remove the perturbations or altering the inputs to reduce their effects.
Another and the oldest defense strategy is adversarial training where the training set of model contains adversarial examples. Both strategies do not generalize well to unseen attacks as they are tailored for a specific set of attacks. On the other hand, a recent defense strategy suggests to use a baseline method and compare its output with the main model to detect attacks. This strategy makes the defense vulnerable to the limitations of the baseline model and the potential mismatches between the main and baseline models for clean samples.

As opposed to the existing defense strategies which either analyze the model inputs or outputs, we propose Layer Regression (LR), a universal lightweight adversarial example detector, which analyzes the changes in the DNN’s internal layer outputs. LR is highly effective for defending various DNN models against a wide range of attacks in different data domains such as image, video, and audio. LR utilizes the difference between the impacts of adversarial samples on early and final layers by performing regression among them. We present the following contributions:

- •
We propose the first universal defense strategy against adversarial examples, which take advantage of the sequential layer-based nature of DNNs and the common objectives of attacks.
- •
We conduct extensive experiments with 672 distinct attack-dataset-model-defense combinations for image recognition, and show that LR outperforms existing methods with a 97.6% average detection performance while the next best performance achieved by the existing defenses is 82.9%. Universality of LR is shown with its superior performance in detecting action recognition attacks and speech recognition attacks.
- •
In addition to its high performance across a wide range of domains, models, and attacks, LR is also the most lightweight defense method. It is orders of magnitude faster than the existing defenses, making it ideal for real-time attack detection.

## 2 Related Works

### 2.1 Adversarial Attacks

The robustness of deep neural networks and their vulnerability against adversarial examples have been investigated since the introduction of FGSM (Goodfellow et al., ). Numerous adversarial attacks have been proposed to generate effective adversarial examples in recent years (Madry et al., ; Croce & Hein, ; Kurakin et al., ; Chen et al., ; Ilyas et al., ; Mumcu & Yilmaz, ; Wang & He, ; Fang et al., ; Gao et al., ). There are two main adversarial attack settings, namely white-box and black-box. While it is assumed that the attacker has access to the target model in the white-box setting, in the black-box setting, the attacker does not have any prior information about the target model.

White box attacks, including FGSM (Goodfellow et al., ), PGD (Madry et al., ), APGD (Croce & Hein, ), generate adversarial examples by maximizing the target model’s loss function and they are usually referred as gradient-based attacks. BIM (Kurakin et al., ) tries to improve gradient-based attack by applying perturbations iteratively.
Transferability based black-box attacks, which is introduced in Papernot et al. (), are one of the most common black-box approach. The idea is to use an attack on a substitute model for generating adversarial examples for unknown target models, utilizing the transferability of adversarial examples to different DNNs. While adversarial examples generated by these attacks are most effective when the substitute model exactly matches the target model as in a white-box attack setting, their success is shown to be transferable even when there is significant architectural differences between the substitute and target models.
Wang & He () introduced VMI and VNI to further extend iterative gradient-based attacks and try to achieve high transferability by considering the gradient variance of the previous iterations. PIF (Gao et al., ) uses patch-wise iterations to achieve transferability. ANDA (Fang et al., ) aims to achieve strong transferability by avoiding the overfitting of adversarial examples to the substitute model.

### 2.2 Adversarial Defenses

Attempting to make changes on the input data for removing the effects of perturbations from adversarial examples is the most common defense strategy.
JPEG compression is studied in several works (Cucu et al., ; Aydemir et al., ; Das et al., ), and it is shown that compressing and decompressing helps to remove of adversarial effects on input images. Xie et al. () uses random resizing and padding on the inputs to eliminate the adversarial effects.
Xu () introduces feature squeezing where they use bit reduction, spatial smoothing, and non-local means denoising to detect adversarial examples.
Several denoising methods (Liao et al., ; Xiong et al., ; Salman et al., ) were proposed to remove adversarial perturbations from the inputs.
Mustafa et al. () uses wavelet denoising and image super resolution as pre-processing steps to create a defense pipeline against adversarial attacks.
Prakash et al. () tries to eliminate adversarial effects by redistributing the pixel values via a process called pixel deflection. Adversarial training is another method which is studied to increase robustness of DNNs, however adversarial training often fails to perform well especially under various attack configurations (Bai et al., ).
In addition, a recent defense strategy which utilizes a baseline model, e.g., Vision Language Models (VLMs), with the assumption that the output of target model and baseline model are close to each other for clean input, but are far away from each other for adversarital input.
A recent example is demonstrated by Mumcu & Yilmaz () where they used CLIP (Radford et al., ) to detect adversarial video examples.

Adversarial training suffers from the increasing number of adversarial attacks which makes this strategy ineffective against adversarial examples which are not represented in the training set. Similarly, developing a universal perturbation removal method that is effective against every attack is not feasible due to continuous advancements in attack techniques. Additionally, since the defender cannot always know whether the input has been attacked, there is a risk of degrading clean inputs and causing false alarms. The baseline methods, which involve using a secondary model, such as VLMs, to detect adversarial examples, rely on the assumption that the secondary model will not be affected by the adversarial samples that are designed against the primary model. However, even without an attack, a mismatch between the models’ predictions may trigger false alarms. Moreover, an attack that compromises both models can easily bypass this defense strategy.

## 3 Detecting Adversarial Examples

Consider a Deep Neural Network (DNN) model $g(\cdot)$ that takes an input $x$ and predicts the target variable $y$ with $g(x)$.
As discussed in Section 2.2, there are three main defense strategies against adversarial attacks: adversarial training, modifying input, and detecting adversarial samples by monitoring changes in output with respect to a baseline.
While the former two focuses on the changes in the input ($x$ vs. $x^{adv})$, the latter utilizes the changes in the output ($g(x)$ vs. $g(x^{adv}))$. Our approach differs from these existing approaches by leveraging the changes within the DNN activations. Instead of analyzing the input $x^{adv}$ or the output $g(x^{adv})$, the proposed defense method analyzes the intermediate steps between $x^{adv}$ and $g(x^{adv})$.

To develop a universal detector that work with any DNN and against any attack, we start with the following generic observation.
Although there are numerous attacks with different approaches to generate adversarial examples, all attacks essentially aim to change the model’s prediction by maximizing the loss $\mathcal{L}$ (e.g., cross-entropy loss) between prediction $g(x^{adv})$ and the ground truth $y$ while limiting the perturbation Fang et al. ():

$$ $\displaystyle\max_{x^{adv}}\mathcal{L}(g(x^{adv}),y)~{}~{}\text{s.t.}~{}~{}\|x ^{adv}-x\|_{\infty}\leq\epsilon.$ (1) $$

Considering this common aim of attack methods and the sequential nature of DNNs, in the following theorem, we show that the impact of adversarial examples on the final layer is much higher than the initial layer. Let us first define a generic DNN $g(\cdot)$ consisting of $n$ layers $a=\{a_{1},a_{2},...,a_{n}\}$. In DNNs, including CNNs, transformers, etc., layers incrementally process the information from the previous layers to compute their respective outputs to the next layer. For example, for a model $g$ where each layer is connected to the previous one, the final output of the model can be formulated as follows:

$$ $\displaystyle g(x)=a_{n}(a_{n-1}(\dots a_{1}(x))).$ (2) $$

For simplicity, we will denote a layer’s output vector with $a_{i}(x)$. Note that, the output of last layer $a_{n}(x)=g(x)$ is typically the class probability vector in classification, and $a_{n-1}(x)$ is referred as the feature vector of the model.

###### Theorem 1 .

Assuming a loss function $\mathcal{L}(g(x),y)$ that is monotonic with $\|g(x)-y\|_{\infty}$, for $n>1$, we have

$$ $d_{n}=\|a_{n}(x^{adv})-a_{n}(x)\|_{\infty}>d_{1}=\|a_{1}(x^{adv})-a_{1}(x)\|_{ \infty}.$ (3) $$

###### Proof.

Since the model $g$ is trained by optimizing the weights $w$ to minimize the loss $\mathcal{L}(g_{w}(x),y)$, i.e.,

$$ $g(x)=\arg\min_{w}\mathcal{L}(g_{w}(x),y),$ (4) $$

we can rewrite Eq. 1 as

$$ $\max_{x^{adv}}\mathcal{L}(g(x^{adv}),g(x))~{}~{}\text{s.t.}~{}~{}\|x^{adv}-x\| _{\infty}\leq\epsilon.$ (5) $$

Note that $a_{n}(x)=g(x)$ and $a_{n}(x^{adv})=g(x^{adv})$ and $\mathcal{L}(g(x^{adv}),g(x))$ is monotonic with $\|g(x^{adv})-g(x)\|_{\infty}$. Hence,
$\|a_{n}(x^{adv})-a_{n}(x)\|_{\infty}$ is maximized while limiting $\|x^{adv}-x\|_{\infty}$ by a small number. Finally, the perturbation aligned with DNN weights is amplified as it sequentially moves through the DNN layers Goodfellow et al. (),

$$ $\|x^{adv}-x\|_{\infty}<\|a_{1}(x^{adv})-a_{1}(x)\|_{\infty}<\|a_{n}(x^{adv})-a _{n}(x)\|_{\infty},~{}n>1.$ $$

∎

Having shown that the impact of an adversarial sample is higher on the final layer output than the first layer output, we next present how to utilize this fact for detecting adversarial samples.

###### Corollary 1 .

Consider a function $f$ which maps $a_{1}(x)$ to $a_{n}(x)$ and is stable in the sense that
$\|f(a_{1}(x))-f(a_{1}(x+\epsilon))\|_{\infty}\leq\delta$
for small $\epsilon$ and $\delta$. Then,

$$ $e_{a}=\|f(a_{1}(x^{adv}))-a_{n}(x^{adv})\|_{\infty}>e_{c}=\|f(a_{1}(x))-a_{n}( x)\|_{\infty}.$ (6) $$

###### Proof.

Since $\|x^{adv}-x\|_{\infty}\leq\epsilon$ from Eq. 1, $f(a_{1}(x^{adv}))$ is close to $f(a_{1}(x))$ due to the stability of $f$. From Theorem 1, $a_{n}(x^{adv})$ is far away from $a_{n}(x)$ compared to the distance between $a_{1}(x)$ and $a_{1}(x^{adv})$. Thus, the estimation error for adversarial samples $e_{a}=\|f(a_{1}(x^{adv}))-a_{n}(x^{adv})\|_{\infty}$ is larger than the error for clean samples $e_{c}=\|f(a_{1}(x))-a_{n}(x)\|_{\infty}$.
∎

###### Theorem 1 .

###### Proof.

###### Corollary 1 .

###### Proof.

### 3.1 Layer Regression

While Theorem 1 provides the theoretical motivation, the result in Corollary 1 provides a mechanism to detect adversarial samples if we can train a suitable function $f$ (Figure 1). We make four approximations to obtain a practical algorithm based on Corollary 1. First, we propose to use a multi-layer perceptron (MLP) to approximate $f$. Second, since $a_{n}(x)$ denotes the predicted class probabilities, we choose the feature vector $a_{n-1}$, which takes unconstrained real values, as the target to train MLP as a regression model. Third, we approximate non-differentiable $\|\cdot\|_{\infty}$ with $\|\cdot\|_{2}$ to train the MLP using the differentiable mean squared error (MSE) loss.
To empirically check the validity of Theorem 1 under these three approximations, we use the ImageNet validation dataset, ResNet-50 He et al. () as target model, and PGD attack Madry et al. () to compute the mean and standard deviation of normalized change in layer 1 $\tilde{d}_{1}=\frac{\|a_{1}(x^{adv})-a_{1}(x)\|_{2}}{\|a_{1}(x^{adv})\|_{2}+\|
a_{1}(x)\|_{2}}$ and layer $n-1$ $\tilde{d}_{n-1}=\frac{\|a_{n-1}(x^{adv})-a_{n-1}(x)\|_{2}}{\|a_{n-1}(x^{adv})
\|_{2}+\|a_{n-1}(x)\|_{2}}$.

Figure: Figure 1: (Left) Theorem 1 shows that the impact of adversarial samples is higher on the final layer than the first layer. Corollary 1 uses this result to prove that the error of a stable estimator is higher for adversarial samples compared to clean samples. (Right) The performance of approximations in proposed detector to Corollary 1 depend on two conflicting objectives: proximity of input vectors for clean and adversarial samples, and training an accurate and stable estimator. (Table) Empirical confirmation of the agreement between the proposed detector with approximations and the theoretical results.
Refer to caption: extracted/5946974/ICLR25/figures/thm_cor.png

In deep neural networks with $n\gg 1$, training an suitable $f$ to estimate the feature vector $a_{n-1}$ using the first layer output $a_{1}$ as the input is a challenging task due to the highly nonlinear mapping in $n-2$ layers. To develop a lightweight detector via MLP, as the fourth approximation, we propose selecting a mixture of early layer outputs as the input to the regression model instead of using only the first layer. Using a mixture of 5th, 8th, and 13th convolutional layers in ResNet-50 as the input, we empirically check Corollary 1 under the same setting used for $\tilde{d}_{1}$ and $\tilde{d}_{n-1}$ by computing the mean and standard deviation of MSE $\tilde{e}_{c}=\|f(a_{1}(x))-a_{n-1}(x)\|_{2}$ for clean images and $\tilde{e}_{a}=\|f(a_{1}(x^{adv}))-a_{n-1}(x^{adv})\|_{2}$ for adversarial images, where an MLP with two hidden layers is used for $f$. Results shown in Figure 1 corroborate Theorem 1 and Corollary 1 under the three approximations. Input selection for MLP is further discussed in this section and ablation study in Section 5.2.

Utilizing the four approximations to Corollary 1 discussed above, we propose a universal and lightweight detection algorithm with the following steps: (i) select a subset of the first $n-2$ layer vectors and generate a new vector $v$ from the selected subset, (ii) feed $v$ into a regression model $m$ to predict the feature vector $a_{n-1}(x)$, (iii) train $m$ by minimizing the mean squared error (MSE) loss $\ell(m(v),a_{n-1}(x))$ in the clean training set devoid of adversarial samples, (iv) decide a test sample is adversarial if the prediction loss is greater than a threshold, $\ell(m(v),a_{n-1}(x))>h$. A pseudo-code of LR is given in Appendix D.

Figure: Figure 2: (Left) Layer selection and slicing operations to form the input vector. (Right) Training and testing procedures of the proposed detector.
Refer to caption: extracted/5946974/ICLR25/figures/method.png

The formation of vector $v$ can be done in various ways, such as using only the $i$th layer vector $v=a_{i}(x)$ or mixture of several layer vectors. To enable larger estimation error $e_{a}$ for adversarial samples than estimation error $e_{c}$ for clean samples, the choice for $v$ should strike a balance between two competing goals, as illustrated in Figure 1: proximity of clean $v(x)$ and adversarial $v(x^{adv})$, and accuracy and stability of estimation function $f$. While training an accurate and stable regression model is more feasible when $v$ is selected from the layers closer to the target layer $n-1$, e.g., $v=a_{n-2}(x)$, such a detector might be less sensitive to adversarial samples since both $a_{n-2}(x)$ and $a_{n-1}(x)$ are expected to be impacted significantly by the attack, i.e., $a_{n-2}(x)$ and $a_{n-2}(x^{adv})$ will not be proximal. On the other hand, while selecting $v=a_{1}(x)$ ensures a reasonably small perturbation in $v$, it also makes obtaining an accurate and stable estimator more challenging. As a result, we propose to select a subset of layer vectors

$$ $a_{r}=\{a_{r1}(x),a_{r2}(x),...,a_{rm}(x)\}$ (7) $$

where $a_{r}\in a$ and $m<n$ is the number of selected layers. From the selected layer vectors, we aim to generate a new vector $v$. However, since the layer vectors are often large due to the operations like convolutions or attentions, to get a specific portion of the selected layer vectors, we define a unique slicing function $s=\{s_{1},s_{2},...,s_{m}\}$ for each layer vector in $a_{r}$. Then, each slicing function is applied to the corresponding layer vector in $a_{r}$ to get the sliced vectors

$$ $s_{r}=\{s_{1}(a_{r1}(x)),s_{2}(a_{r2}(x)),...,s_{m}(a_{rm}(x))\}.$ (8) $$

Finally, the vector $v$ is generated by concatenating the vectors in $s_{r}$:

$$ $\displaystyle v=[s_{1}(a_{r1}(x)),s_{2}(a_{r2}(x)),\ldots,s_{m}(a_{rm}(x))].$ (9) $$

The proposed layer selection and slicing process is summarized in Figure 2.

During the training, only the clean input samples are used. After the training, the loss is expected to be low for clean inputs and high for adversarial inputs. Thus, an adversarial example can be detected by comparing the loss $\ell(m(v),a_{n-1}(x))$ with a threshold $h$:

$$ $d=\begin{cases}\text{$x$ is adversarial}&\text{if $\ell>h$}\\ \text{$x$ is not adversarial}&\text{if $\ell\leq h$},\\ \end{cases}$ (10) $$

The threshold $h$ is determined by calculating the loss for a set of clean inputs $\beta=\{\ell_{1},\ldots,\ell_{K}\}$, where the losses in $\beta$ are sorted in ascending order, i.e., $\ell_{1}\leq\ell_{2}\leq\dots\leq\ell_{K}$. $h$ is selected as the $\theta$th percentile of the clean training losses: $h=\beta[\lfloor K\theta/100\rfloor]$ where $\lfloor\cdot\rfloor$ denotes the floor operator, and $\beta[i]$ denotes the $i$th element of $\beta$.

## 4 Experiments and Analyses

In this section, we evaluate the performance of our method and compare it against 7 existing defense methods. Our extensive experiments are conducted on 2 widely used image datasets, with 6 image classification models and 7 adversarial attacks.

Defenses: The following defense methods are used in the experiments: JPEG compression (JPEG) (Das et al., ), Randomization (Random)(Xie et al., ), Deflection (Deflect) (Prakash et al., ), VLAD (Mumcu & Yilmaz, ), Feature Squeezing (FS) Xu (), Wavelet denoising (Denoise) and super resolution (WDSR) (Mustafa et al., ). Since VLAD and FS were proposed as detectors in their respective papers, we use their official implementations. The remaining methods were proposed to increase robustness by altering the inputs to remove perturbations. For this reason, we obtain a detection method from them by comparing the predictions after and before the methods are applied. The case the predictions match indicates no attack and a mismatch indicates an attack.

Attacks: BIM (Kurakin et al., ), PGD (Madry et al., ), PIF (Gao et al., ), APGD (Croce & Hein, ), ANDA (Fang et al., ), VMI and VNI (Wang & He, ) attacks are used to generate adversarial examples during the experiments. We consider the most challenging case for the detector, the white-box attack scenario, in which the attacker has full access to the classification model, i.e., no mismatch between the surrogate model and actual model.

Models: To represent the different architectures we used three CNN-based image classification models, VGG19 Simonyan & Zisserman (), ResNet50 He et al. (), Inceptionv3 Szegedy et al. (); and three transformers-based models, ViT Dosovitskiy (), DeiT Touvron et al. (), LeViT Graham et al. ().

Datasets: The experiments are conducted using the validation set of ImageNet dataset (Russakovsky et al., ) and the CIFAR-100 dataset (Krizhevsky et al., ). For testing, the clean set comprises all images that are correctly classified by the target models. An adversarial set is formed for each attack-target model combination by gathering the attack’s adversarial images misclassified by target model.

LR training: For each model, an MLP with 2 hidden layers is trained as the LR detector. The details of the chosen $a_{r}$ subsets, detectors, $s_{r}$ slicing functions, and training parameters are detailed in Appendix C.

Evaluation: The commonly used the Area Under Curve (AUC) metric from the Receiver Operating Characteristic (ROC) curve is used to evaluate the attack detection performance of defense methods. ROC curve shows the trade-off between true positive rate (i.e., ratio of successfully detected adversarial samples to all adversarial samples) and false positive rate (i.e., ratio of false alarms to all clean samples).

### 4.1 AUC Results

Table: Table 1: Comparison between 8 defenses in terms of detection AUC against 7 attack methods targeting 6 models using ImageNet and CIFAR-100 datasets.

Figure: Figure 3: Histogram of AUC values for LR and VLAD on (Left) ImageNet (Right) CIFAR-100.
Refer to caption: extracted/5946974/ICLR25/figures/pt_hist_imagenet.png

In Table 1, we report the AUC scores for JPEG, Random, Deflect, VLAD, Denoise, WDSR, FS and our method, LR, against the BIM, PGD, PIF, APGD, ANDA, VMI and VNI attacks targeting 7 models, namely Vgg19, ResNet50, Inceptionv3, ViT, DeiT, LeViT, on two datasets, ImageNet and CIFAR-100.
In every experimental setting, with different attacks, target models, and datasets, our proposed method outperforms the existing defense methods by a wide margin. Compared to LR’s average AUC of $0.976$ over ImageNet and CIFAR, the best performance among the existing methods remains at $0.829$.
More importantly, our method is robust to changing targets and attacks, as indicated by its small standard deviation. While the other defense methods are effective against certain target-attack combinations, they fail to generalize this to a wide range of settings. For instance, on ImageNet, JPEG, Random, and FS perform better with the transformer models, however they rarely exceed the random guess performance with the CNN models. While VLAD consistently achieves good performance on ImageNet, its performance significantly drops on CIFAR-100, possibly due to its dependency on CLIP. When CLIP is fooled by the attacks, VLAD also fails. Moreover, VLAD is orders of magnitude slower than LR, as shown in Figure 5 and Table 5.

The histogram of AUC values for LR in Figure 3 clearly demonstrate the robustness of our method compared to its main competitor, VLAD. ANDA, which is the most recent and state-of-the-art attack method in the literature, troubles our detector the most. However, LR still maintains an average AUC of $0.954$ and $0.946$ against ANDA over the six target models on ImageNet and CIFAR-100, respectively. The average AUC values of LR against BIM, PGD, PIF, APGD, VMI, and VNI on (ImageNet, CIFAR-100) are as follows: $(0.993,0.979),(0.987,0.960),(0.990,0.976),(0.981,0.968),(0.994,0.990),(0.983,.
976)$. Interestingly, InceptionV3 is the easiest model for LR to defend against attacks trained on CIFAR-100 with a perfect detection score while the average AUC of LR for InceptionV3 with ImageNet is $0.965$. The average AUC of LR values for Vgg19, ResNet50, ViT, DeiT, and LeViT with (ImageNet, CIFAR-100) are as follows: $(0.991,0.998),(0.974,0.979),(0.990,0.952),(0.996,0.925),(0.981,0.970)$.

### 4.2 Real-Time Detection Performance

Figure: Figure 4: The proposed detector is both universal (high AUC across all scenarios) and lightweight (fastest among all existing defenses).
Refer to caption: extracted/5946974/ICLR25/figures/pt_avg.png

Real-time performance is a crucial aspect of an attack detection method. A detection mechanism must always run alongside the DNN model to ensure timely detection of adversarial examples. Here, we compare the real-time performance of the defense methods used in the experiments. For each defense method, we processed 1,000 samples from ImageNet with the defense methods and took the average of processing times. In Table 5, for each defense method, we show the processing time per sample (PTS) in seconds. Our method is significantly faster than the others with only 0.0004 seconds. WDSR and VLAD are the slowest methods with 0.2611 and 0.1431 seconds respectively. Figure 5 demonstrates the trade-off between PTS and average accuracy of the existing defense methods. Our method exhibits an outlying performance by significantly beating the existing methods in both PTS and average detection AUC. The processing times are measured using a computer with an NVIDIA 4090 GPU, AMD Ryzen 9 7950X CPU, and 64 GB RAM.

## 5 Ablation Study

### 5.1 Effect of Attack Strength

Figure: (a) ResNet & PGD
Refer to caption: extracted/5946974/ICLR25/figures/eps-resnet-pgd.png

Adversarial attacks often use a designated parameter $\epsilon$ to adjust the amount of perturbation on adversarial examples. For the experiments in Section 4, we used the default attack settings that are proposed by the authors. In this ablation study, we investigate the performance of defense methods against PGD and BIM attacks with different $\epsilon$ values. In the original implementation of PGD and BIM, attack strength parameter $\epsilon$ is set to 0.03. In addition to the original $\epsilon$, we also generated attacks by setting $\epsilon$ to 0.01, 0.09, 0.12, 0.15 and 0.3 and attacked ResNet and ViT.

Figure 6 plots the performances of defense methods for ResNet-PGD, ResNet-BIM, ViT-PGD and ViT-BIM model-attack pairs. We noticed a small performance drop in our method when the attack strength has the smallest value of 0.01. However, higher $\epsilon$ values resulted in higher AUC in every case. This is an expected behaviour since our method depends on the effects of the perturbation on DNN layers. In other defense methods, while VLAD and Deflect experience only small changes under stronger attacks, remaining methods are greatly affected by the $\epsilon$ value, especially while defending ResNet.

### 5.2 Effects of Layer Vector Choice

For the experiments in Section 4, we used three layer vectors to form $v$, i.e., $m=3$ in Eq. 9. Since the number of combinations for layer selection and slicing yields an intractable search space for extensive optimization, we performed optimization over a limited set of representative options. Table 2 summarizes the results of a preliminary experiment on CIFAR-100, which is conducted with DeiT as the target model and PGD and PIF as the adversarial attacks. In this experiment, we considered 25 attention layers of the model and trained our detectors by forming $v$ in four different ways: (1) using only the first attention layer vector $a_{1}$, (2) using only the last attention layer vector $a_{25}$, (3) combining the vectors from fifth, sixth, and seventh attention vectors $[a_{5},a_{6},a_{7}]$, (4) and combining the vectors from eighth, thirteenth, and seventeenth attention vectors $[a_{8},a_{13},a_{17}]$. The best strategy turns out to combining vectors from early layers $[a_{5},a_{6},a_{7}]$ as it strikes a good balance in the trade-off between the two conflicting goals (Figure 1): proximity of $v(x)$ and $v(x^{adv})$, and accuracy and stability of estimator $f$. Additionally, having multiple layers and slicing functions can create randomness in each LR implementation, which makes developing an attack against our detection system harder.
The layer selection and slicing strategies that gave the best results reported in Table 1 are listed in Appendix C.

**Table 2: Impact of layer selection on detection AUC.**
| Attack | $a_{1}$ | $[a_{5},a_{6},a_{7}]$ | $[a_{8},a_{13},a_{17}]$ | $a_{n-2}$ |
| --- | --- | --- | --- | --- |
| PGD | 0.697 | 0.867 | 0.751 | 0.567 |
| PIF | 0.744 | 0.972 | 0.746 | 0.521 |

## 6 Applicability in Other Domains

LR is applicable in every domain where DNNs are used. In this section we demonstrate its performance in two other domains, video action recognition and speech recognition. In Appendices A and G, we provide more information about experimental details that are used in this section. Moreover, we provide additional results on another application, traffic sign recognition, in Appendix F.

### 6.1 LR for Video Action Recognition

In this section, we implement LR against video action recognition attacks and compare its performance with existing defenses designed for action recognition models, namely Advit (Xiao et al., ), Shuffle (Hwang et al., ), and VLAD (Mumcu & Yilmaz, ). In the experiments, PGD-v attack (Mumcu & Yilmaz, ) and Flick attack (Pony et al., ) are used to target MVIT (Fan et al., ) and X3D (Feichtenhofer, ). The experimental settings in Mumcu & Yilmaz () on Kinetics-400 (Kay et al., ) dataset are followed. The results in Table 3 show that LR outperforms the other defenses with an average AUC of 0.93%, followed by VLAD which achieves 0.91%.

**Table 3: Comparison between defense methods in terms of detection AUC against attack methods targeting video action recognition models.**
|  |  | Advit | Shuffle | VLAD | LR (ours) |
| --- | --- | --- | --- | --- | --- |
| MVIT | PGD-v | 0.93 | 0.98 | 0.93 | 0.99 |
| Flick | 0.34 | 0.65 | 0.87 | 0.89 |  |
| X3D | PGD-v | 0.92 | 0.76 | 0.97 | 0.95 |
| Flick | 0.54 | 0.59 | 0.90 | 0.92 |  |
|  | Average | 0.68 | 0.74 | 0.91 | 0.93 |

### 6.2 LR for Speech Recognition

Figure: Figure 7: Clean and adversarial samples for speech recognition with ground truth in box, recognized text, word error rate (WER), and MSE of proposed LR.
Refer to caption: extracted/5946974/ICLR25/figures/waw.png

To demonstrate LR’s wide applicability, in addition to computer vision, we also demonstrate its performance against a speech recognition attack. As target model, we use Wav2vec (Schneider et al., ) model, which is trained on LibriSpeech (Panayotov et al., ) dataset. Model is attacked with FGSM (Goodfellow et al., ). LR achieves an average AUC of $0.99$. Figure 7 illustrates some attacked and clean samples from LibriSpeech, along with the MSE values of LR. As shown in the figure, LR can even detect stealthy attacks which do not raise the word error rate (WER) much while distorting the recognized speech. Remarkably, while the WER of the first adversarial example in the figure is lower than the WER of the second clean example ($0.4$ vs. $0.5$), the LR loss for this stealthy adversarial sample is more than ten folds greater than that of the second clean example ($1.6$ vs $0.13$).

## 7 Conclusion

Although there are effective defense methods for specific model-attack combinations, their success do not generalize to all popular models and attacks. In this work, we filled this gap by introducing Layer Regression (LR), the first universal method for detecting adversarial examples. In addition to its universality, LR is much more lightweight and faster than the existing defense methods. By analyzing the common objectives of attacks and the sequential layer-based nature of DNNs, we proved that the impact of adversarial samples is more on the final layer than the first layer. Motivated by this fact, LR trains a multi-layer perceptron (MLP) on clean samples to estimate the feature vector using a combination of outputs from early layers. The estimation error of LR for adversarial samples is typically much higher than the error for clean samples, which enables an average AUC of $0.982$ and $0.970$ on the ImageNet and CIFAR-100 datasets across 6 models and 7 attacks. With extensive experiments, we showed that LR outperforms the existing defenses in image recognition by a wide margin and also provides highly effective detection performance in distinct domains, namely video action recognition and speech recognition. One caveat that needs to be studied in future works is the possibility of training an attack model that can learn to fool the target model and LR together.

## 8 Reproducibility Statement

We provide detailed information about our experimental settings and training methods in Section 4 and Appendix C. In section 3.1 we offer a step-by-step explanation of our detection algorithm, In Appendix D, a PyTorch-like pseudo code is provided. All trained models, code, and the project page will be shared publicly after the paper is officially published in a peer-reviewed venue.

## Appendix A More Related Works from Other Domains

Adversarial examples are studied on several other domains including video action recognition (Pony et al., ), traffic sign recognition (Hsiao et al., ), object detection (Zhao et al., ), video anomaly detection (Mumcu et al., ), and speech recognition (Żelasko et al., ). For instance, flickering attack (Flick) (Pony et al., ) tries to attack action recognition models by changing the RGB stream of the input videos. Hsiao et al. () investigates the effects of natural light on traffic signs and use it to generate adversarial examples.

Advit (Xiao et al., ) is a detection method introduced for videos. It generates pseudo frames using optical flow and evaluates the consistency between the outputs for original inputs and pseudo frames to detect attacks. Another defense method, Shuffle (Hwang et al., ), tries to increase the robustness of action recognition models by randomly shuffling the input frames. (Mumcu & Yilmaz, ) proposed to train a lightweight VLM and use it for adversarial traffic sign detection. In speech recognition, defenses like denoising or smoothing are studied against adversarial examples (Żelasko et al., ).

## Appendix B More details on experimental settings

From the validation set of ImageNet (Russakovsky et al., ), we used 40,000 images
to train the detectors and the remaining 10,000 for testing. For CIFAR-100 (Krizhevsky et al., ) has 100 classes and there
are 500 training images and 100 testing images per class, resulting in a total of 50,000 training and
10,000 test images. During the tests, only the correctly classified images by the target models were used. Total number for test images for each specific model and dataset is given in Table 4.

**Table 4: Number of test images used for each model.**
|  | Vgg19 | ResNet50 | Inceptionv3 | ViT | DeiT | LeViT |
| --- | --- | --- | --- | --- | --- | --- |
| ImageNet | 4257 | 7701 | 7410 | 8457 | 7907 | 7639 |
| CIFAR-100 | 7045 | 8315 | 8089 | 8544 | 8667 | 8359 |

VLAD (Mumcu & Yilmaz, ) was originally proposed for video recognition attacks, with the initial implementation designed for videos consisting of 30 frames. In the experiments conducted in Section 4, we used the official VLAD implementation. However, instead of averaging the scores across 30 frames, we applied it to a single image.

## Appendix C Selected subset vectors during LR training

A specific subset of layer vectors $a_{r}$, as described in equation 7, is chosen for each target model that is used during the experiments in Section 4. For the models, Pytorch Image Models (timm) (Wightman, ) is used.

Then, For

- 1.
Resnet50: Layers have the name conv2 were filtered, then among 15 conv2 layers, 5th, 8th and 13th layers, for all ImageNet and CIFAR-100 tests
- 2.
InceptionV3: Layers have the name conv were filtered, then among 94 conv layers, 15th, 25th and 35th layers, for all ImageNet and CIFAR-100 tests
- 3.
Vgg19: Layers which have the name features were filtered, then among 37 features layers, 8th, 13th and 17th layers, for all ImageNet and CIFAR-100 tests
- 4.
ViT: Layers which have the name attn.proj were filtered, then among 23 attn.proj layers, 8th, 13th and 17th layers, for all ImageNet and CIFAR-100 tests
- 5.
DeiT: Layers which have the name attn.proj were filtered, then among 24 attn.proj layers, 8th, 13th and 17th layers for ImageNet tests, 5th, 6th, 7th layers for CIFAR-100 tests
- 6.
LeViT: Layers which have the name attn.proj were filtered, then among 12 attn.proj layers, 3th, 5th and 7th layers for ImageNet tests, 5th, 6th, 7th layers for CIFAR-100 tests

were used as $a_{r}$ subsets. Before concatenating the $a_{r}$ vectors, a specific slicing function for each vector is applied as described in equation 8. The specific slicing functions for each corresponding $a_{r}$ are detailed below:

- 1.
Resnet50: $[:5,:28,:28]$, $[:50,:7,:7]$ and $[:10,:14,:14]$.
- 2.
InceptionV3: $[:3,:35,:35]$, $[3:,35:,35]$ and $[:3,:17,:17]$.
- 3.
Vgg19: $[:5,:25,:25]$, $[:5,:25,:25]$ and $[:5,:25,:25]$.
- 4.
ViT: $[:,:4:200]$, $[:,:4:200]$ and $[:,:4:,200]$.
- 5.
DeiT: $[:,:4,:200]$, $[:,:4,:200]$ and $[:,:4,:200]$.
- 6.
LeViT $[:4,:14:,14]$, $[:14,:7,:7]$ and $[:14,:7,:7]$.

The vector v is generated by concatenating the sliced $a_{r}$ vectors as described in equation 9. After acquiring $v$ for a model, an MLP with two hidden layers trained to minimize the MSE loss between $v$ and the feature vector $a_{n-1}$. Adam optimizer with $3\cdot 10^{-4}$ learning rate is used for the training.

## Appendix D Pseudo-Code for LR

In section 3.1, we explain our detection algorithm in details. Here, in Algorithm 1, we also provide a PyTorch Paszke et al. () like pseudo code for LR.

Figure: Algorithm 1 Linear Regression (LR)

## Appendix E Visualized adversarial examples

Figure: Figure 8: Adversarial examples generated with BIM (Kurakin et al., ), PGD (Madry et al., ), PIF (Gao et al., ), APGD (Croce & Hein, ), ANDA (Fang et al., ), VMI and VNI (Wang & He, ) by attacking target model ResNet50 (He et al., ). First column represents the clean samples.
Refer to caption: extracted/5946974/ICLR25/figures/attack_viz.png

Figure: Figure 9: Visualization perturbations generated with BIM (Kurakin et al., ), PGD (Madry et al., ), PIF (Gao et al., ), APGD (Croce & Hein, ), ANDA (Fang et al., ), VMI and VNI (Wang & He, ) by attacking target model ResNet50 (He et al., ). First row shows the clean sample and corresponding adversairal example for each attack. Second row demonstrates the noises added to the clean sample by each attack.
Refer to caption: extracted/5946974/ICLR25/figures/adv_perturbations.png

Figure: Figure 10: Effects of different attack strength values on a sample. The attack strength parameter $\epsilon$ is increased in the direction of the arrow. In the first sample, there is no attack. Samples are generated with adversarial attack PGD (Madry et al., ) and target model ResNet50 (He et al., )
Refer to caption: extracted/5946974/ICLR25/figures/at_str.png

## Appendix F Additional Ablation study: LR in traffic sign detection

**Table 5: Detection AUC of LR against four attacks targeting ResNet50 in the traffic sign recognition task.**
|  | FGSM | PGD | Patch | Light | Average |
| --- | --- | --- | --- | --- | --- |
| LR | 0.97 | 0.99 | 0.95 | 0.94 | 0.96 |

As an additional experiment, we implement LR against attacks that target traffic sign recognition. In this study, ResNet50 is used as target model and attacked with FGSM(Goodfellow et al., ), PGD(Madry et al., ), Light(Hsiao et al., ) and Patch (Ye et al., ) attacks.
In Table 5, we show that LR achieves an average AUC score of 96%, which further proves the applicability and success of our detection method across different domains.

## Appendix G Details of Ablation Study & Other Domain Experiments

For Section 6.1, the experimental settings detailed in Mumcu & Yilmaz () is followed: ”A subset of Kinetics-400 (Kay et al., ) is
randomly selected for each target model from the videos
that are correctly classified by the respective model. For
each subset, the total number of the videos are between
7700 and 8000 and each class has at least 3, at most 20
instances. An adversarial version of the remaining
20% portion is generated with each adversarial attack, in a
way that they cannot be correctly classified by the models.
Then the adversarial set is used for evaluation along with the
clean versions.”
Similarly to main experiments, we trained an MLP with 2 hidden layers with the same training hyper-parameters described in Appendix C. For MVIT (Fan et al., ) and CSN (Tran et al., ) models, layers which have the name conv_a and attn.proj were filtered respectively. While for both of the models 3th 5th and 7th layers used to form subset $a_{r}$, for CSN (Tran et al., ) additional layers 4th, 6th and 8th were also used. $[:,:4,:200]$ and $[:,:4,:3,:7,:7]$ were used as slicing functions for MVIT (Fan et al., ) and CSN (Tran et al., ) respectively.

For Section 6.2, an MLP with 2 hidden layers with the same training hyper-parameters described in Appendix C is trained. For Wav2vec (Schneider et al., ) model, layers which have the name attention.dropout were filtered, and 3th layer used to form $a_{r}$. As slicing function $[:,:4,:20,:10]$ is selected. While 500 sound clips from LibriSpeech dataset used for experiments, 2000 sound clips saved for training.

For Appendix F, we use the experimental settings as demonstrated in Mumcu & Yilmaz () and use the GTSRB (Stallkamp et al., ) dataset which includes 43 classes of traffic signs, split into 39,209 176 training images and 12,630 test images. LR detector is trained with the same settings that are specified for Resnet50 in Appendix C.

## Peer Reviews

confidence: 4
contribution: 1
initial_rating: 3
presentation: 2
questions: 1. **Input Selection Heuristic:** The selection of early layer activations for the regression model's input seems somewhat arbitrary. While the paper mentions a trade-off between proximity of clean and adversarial inputs and the accuracy of the estimator, a more principled approach for input selection would strengthen the method.
2. **Lack of Robustness Analysis:** The paper primarily focuses on white-box attacks. The performance against more realistic ***black-box attacks*** is not evaluated. Furthermore, the robustness of LR itself against ***adaptive attacks***, where the adversary is aware of the defense mechanism, is not discussed. An attacker could potentially craft perturbations that minimize the change in the selected early layer activations while still maximizing the classification loss.
3. **Overfitting Potential:** Training the MLP on clean data only might lead to overfitting and poor generalization to unseen adversarial examples, especially considering the high dimensionality of the feature vectors.
4. **Hyperparameter sensitivity:** The method requires setting a threshold value, which could be sensitive to different scenarios.
5. **Inadequate Evaluation:** The baseline methodology used is outdated and not compared to the most recent SOTA **[R1], [R2]**.

**[R1]** What You See in Not What the Network Infers: Detecting Adversarial Examples Based on Semantic Contradiction.   
**[R2]** Detecting adversarial data by probing multiple perturbations using expected perturbation score.
soundness: 2
strengths: 1. **Theoretical Foundation.** Mathematical proof supporting the core concept and has a clear theoretical justification for why the method works.

2. **Lightweight:** Using a relatively small MLP for regression makes LR computationally efficient, and suitable for real-time detection.
summary: This paper proposes Layer Regression (LR), a universal and lightweight method for detecting adversarial examples in DNNs. The key innovation lies in analyzing the changes in DNN's internal layer outputs rather than focusing on input modifications or output comparisons like previous approaches. The authors provide theoretical justification through a theorem showing that adversarial impacts are stronger in the final layers compared to the initial layers.
weaknesses: See questions.

---

confidence: 4
contribution: 3
initial_rating: 3
presentation: 3
questions: - Does the theorem 1 hold for arbitrary deep neural networks? I would like to show you a strict mathematical proof of theorem 1.
- Is the proposed method able to detect adversarial examples with a minimal norm of adversarial perturbation?
soundness: 1
strengths: - The proposed method empirically shows meaningful improvement in detection AUC compared to other baseline defenses among various architectures.
- The motivation is well explained and partially justified through theoretical analysis.
summary: This study proposes a universal and lightweight detection method for adversarial examples to defend deep neural networks from the threat of adversarial examples. The proposed detector is trained to predict the difference in feature vectors of benign inputs among layers. When the loss of the input is higher than a pre-defined threshold, the detector treats the input as an adversarial example. The effectiveness of the proposed detector is justified through theoretical analysis and extensive experiments.
weaknesses: - The proof of theorem 1 seems to miss the important assumption in the referred paper (Goodfellow et al., 2014). Goodfellow et al. claim that the perturbation is linearly amplified as it moves through linear models, but there are no theoretical results for nonlinear models.
- The effectiveness of the proposed detector could be further emphasized by investigating their detection performance against attacks that produce adversarial examples with minimal perturbation norms because the tested attacks are limited to maximize attack success rates under a given attack budget.

---

confidence: 5
contribution: 2
initial_rating: 5
presentation: 2
questions: 1. What will the detection performance of LR be when facing targeted attacks?
soundness: 2
strengths: 1. The motivation of the proposed LR is clearly stated.
2. According to the experimental results, LR detects adversarial examples with high efficiency.
3. Experiments in other domains are implemented to prove the universality of LR.
summary: This paper proposes a detection method named Layer Regression (LR), which assumes that the impact of adversarial examples on the final layer is much larger than the initial layer. The proposed LR can achieves high detection performance, and experimental results show that it can be applied in different tasks.
weaknesses: 1. The detection baselines are not strong enough. Some strong baselines, like [1][2][3], are not included, which makes the experimental results less convincing.
2. There is a lack of adaptive attack against LR, and the adaptive attack is important to evaluate the detection performance.
3. According to Section C in the Appendix, the subset of layer vectors needs to be selected for each model, and the dataset may sometimes influence the choice of layers, reducing the practicality of LR.

[1] Tian, Jinyu, Jiantao Zhou, Yuanman Li, and Jia Duan. "Detecting adversarial examples from sensitivity inconsistency of spatial-transform domain." In Proceedings of the AAAI Conference on Artificial Intelligence, vol. 35, no. 11, pp. 9877-9885. 2021.
[2] Yang, Yijun, Ruiyuan Gao, Yu Li, Qiuxia Lai, and Qiang Xu. "What you see is not what the network infers: Detecting adversarial examples based on semantic contradiction." NDSS 2022.
[3] Zhang, Shuhai, Feng Liu, Jiahao Yang, Yifan Yang, Changsheng Li, Bo Han, and Mingkui Tan. "Detecting adversarial data by probing multiple perturbations using expected perturbation score." In International conference on machine learning, pp. 41429-41451. PMLR, 2023.

---

confidence: 5
contribution: 1
initial_rating: 3
presentation: 3
questions: Do you believe this paper will be robust to adaptive attacks, as discussed above?
soundness: 1
strengths: Defending against adversarial examples is an important and interesting challenge.
summary: This paper introduces a technique to detect adversarial examples. The defense works by studying the activations of the model to notice suspicious patters that are not present in the clean data. It presents evidence of its efficacy by evaluating against a suite of attacks, and compares to several prior defenses from the literature.
weaknesses: Unfortunately, it appears unfamiliar with the (vast) literature on this topic and the paper does not present convincing evidence that it will be robust to adaptive attacks.

I would particularly recommend the authors begin by reviewing Carlini & Wagner "Adversarial Examples Are Not Easily Detected: Bypassing Ten Detection Methods", and Tramer "Detecting Adversarial Examples Is (Nearly) As Hard As Classifying Them". The latter paper, in particular, shows that the results claimed here would imply a nearly perfectly robust classifier. Then, I would recommend the authors read related papers on detecting adversarial examples ["The Odds are Odd", "Asymmetrical Adversarial Training"]. After this, it could be then useful to study how these defenses were broken in "On adaptive attacks to adversarial example defenses".

What this paper presents---an evaluation against a large set of fixed attacks---is not sufficient for arguing adversarial robustness, and I can not recommend acceptance at this point.

(I would also recommend changing the title of this paper. There are 50+ papers on detecting adversarial examples.)

---

confidence: 5
contribution: 1
initial_rating: 1
presentation: 2
questions: Some questions:

- In the abstract, the authors claim that their method is "applicable across different domains, such as image, video, and audio." However, I can only find experiment results on CIFAR-100 and ImageNet, so where are the results on video and audio?

- The authors claim that their LR method can detect unseen attacks. Where are related experiments? For example, can LR method trained on $\ell_{\infty}$ attacks detect $\ell_{2}$ or $\ell_{0}$ attacks?

- Why there is no experiments on CIFAR-10? CIFAR-10 is the most commonly used dataset in the adversarial literature.
soundness: 1
strengths: I tried, but it's difficult to write down any points that deserve to be called Strengths for an ICLR-submitted paper.
summary: This paper proposes a universal method for detecting adversarial examples by analyzing the layer outputs of deep neural networks. The authors claim to have theoretical justifications and experiments to demonstrate the effectiveness of their method on any DNN architecture and its applicability across multiple domains, including image, video, and audio. Empirical experiments are done on CIFAR-100 and ImageNet.
weaknesses: The weaknesses of this paper include:

- **The proof of Theorem 1 is wrong.** The proof bases on that "Finally, the perturbation aligned with DNN weights is amplified as it sequentially moves through the DNN layers (Goodfellow et al. 2014)", which is an *empirical observation*, not a theoretical conclusion. I was shocked that the authors treat an empirical observation as a formal Theorem, and it's easy to construct a counter-example DNN that violate Theorem 1.

- **Non-adaptive evaluations.** In Line 290-292, the authors claim that "We consider the most challenging case for the detector, the white-box attack scenario, in which the attacker has full access to the classification model". This is NOT a white-box scenario for detection, because *the authors did not assume that the attacker has access to the detection model*. The authors should design adaptive attacks [1,2], where the attacker has full access to both the classification and detection models.

- **False AUC values.** As indicated in [3], a detection AUC value can be converted into a classification defense accuracy. Up to now, the state-of-the-art defenses as listed on RobustBench [4] is less than 45% acc (CIFAR-100), which cannot match the mostly >0.99 AUC values reported in this paper.

- **The baselines are weak.** The majority of defense baselines in this paper are simple input processing methods like JPEG, which is far from a fair comparison for a paper submitted in 2024.


References:\
[1] Adversarial examples are not easily detected: Bypassing ten detection methods. AISec 2017\
[2] Obfuscated gradients give a false sense of security: Circumventing defenses to adversarial examples. ICML 2018\
[3] Detecting Adversarial Examples Is (Nearly) As Hard As Classifying Them. ICML 2022\
[4] https://robustbench.github.io/