{'fraction_non_alphanumeric': 0.03958974358974359, 'fraction_numerical': 0.015316239316239317, 'mean_word_length': 4.753737214791503, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Locally optimal detection of stochastic targeted universal adversarial perturbations

Deep learning image classifiers are known to be vulnerable to small adversarial perturbations of input images. In this paper, we derive the locally optimal generalized likelihood ratio test (LO-GLRT) based detector for detecting stochastic targeted universal adversarial perturbations (UAPs) of the classifier inputs. We also describe a supervised training method to learn the detector's parameters, and demonstrate better performance of the detector compared to other detection methods on several popular image classification datasets.


INTRODUCTION
Deep neural network (DNN) based classifiers are known to be vulnerable to small carefully crafted perturbations added to their inputs. The adversarial perturbations can be crafted using a local neighborhood search around an input, such as by moving along the gradient of the classifier's logits [1], [2]. The perturbation can either change the prediction of the classifier to anything else (in which case it is called non-targeted perturbation), or force the classifier's output to lie in a certain target class (targeted perturbation). Moreover, small universal adversarial perturbations also exist, which can fool a classifier on a significant fraction ( 75%) of the inputs [3] (see Figure  1). UAPs are a serious concern for many practical applications such as autonomous driving, which rely on DNN based models for their perception.
Current strategies to defend a classifier against adversarial perturbations fall into two categories: (1) adapting the training algorithms to learn models which are more robust, using for example adversarial training [6][7][8], (2) detect and possibly rectify the adversarially perturbed inputs [9][10][11]. While adversarial training has shown improvement of the DNN against both input dependent and input independent perturbation in images, the improved robustness often come at expense of accuracy on unperturbed inputs [8]. This robustness-accuracy tradeoff is believed to be fundamental in some of the learning problems [12]. The detection methods take a different approach of defence, wherein the defended classifier remains unchanged. The detector extracts discriminative features between the unperturbed and adversarially perturbed inputs, and a simple binary classifier is used on these features to classify the input [11], [13].
Most existing detection methods consider input-dependent perturbations. Only a few discuss input-independent perturbations such as [13], [14]. Akhtar and Liu et al [13] trains a perturbation rectifying network (PRN), which processes the received input image to obtain a rectified image. The difference between the rectified image and the received image is transformed using the Discrete Cosine Transform (DCT), and fed into a binary linear classifier to predict if the input is unperturbed or adversarially perturbed. The detector achieved high classification accuracy against non-targeted UAPs on ImageNet dataset [13]. However, a drawback of the PRN based detector is its lack of interpretability due to its complex functional form. In contrast, Agarwal et al. [14] use a simple interpretable detector that performs principal component analysis (PCA) on an image, and train a support vector machines (SVM) based linear classifier on the PCA score vectors of the image. The detector is shown to achieve low classification error rates for UAPs obtained using Fast Feature Fool [15] and Moosavi et al's iterative procedure [3] on face databases. One shortcoming of both the PRN and PCA based detectors is that the detectors are trained and evaluated for only non-targeted UAPs that produces high fooling rates on the classifier. But the output of the classifier against non-targeted UAPs spans only a few labels [3]. Hence, it is not clear if the detection performance generalizes to more diverse targeted UAPs whose fooling rate might be slightly lower but still significant for many applications.
In this paper, we consider locally optimal (LO) hypothesis testing for detection of the targeted UAPs in an input to a classifier. LO detectors are more interpretable than other detection methods for small-norm UAPs. LO detectors were earlier described in [9,10], for the setting of detecting finitely many perturbations of the input that are known to the detector. Here, we derive a locally optimal generalized likelihood ratio test (LO-GLRT) for detecting random targeted UAPs in an input of a classifier. Then we also consider a special case of the test, assuming product multivariate Gaussian distribution on the input. The resulting detector exhibits much simple form than other detectors. We also describe a supervised training method for learning the detector's parameters. We then evaluate the detector on three key metrics and show that LO-GLRT detector achieves better performance than PRN and PCA based detectors on all the metrics.

UNIVERSAL ADVERSARIAL PERTURBATIONS
Let X = R d denote the input space and Y denote a set of labels. Denote by (x, y) ∈ X × Y a pair of input and corresponding label drawn according to a joint distribution P x,y . Also, suppose P x denote the marginal distribution on input x. Further, let f denote a classifier and f (x) ∈ Y denote the classifier's output for input x. Let H(p, q) denotes the crossentropy of two probability vectors p and q, andπ f (x) denotes the conditional output probability vector of the classifier f , given an input x. Denote by A an attacker, who chooses a UAP h ∈ R d to fool the classifier f . Also, let [m] denotes the set {1, 2, . . . m}, Several recent works discuss methods to find both targeted and non-targeted UAPs [3,16,17]. For non-targeted UAPs, Moosavi et al. [3] were first to propose an algorithm for generating the perturbations. However, their method is computationally inefficient. Shafahi et al. [17] use a more tractable approach by solving the optimization problem, (1) over N training examples using minibatch stochastic gradient descent (SGD) algorithm, with truncated cross entropy loss function (ŷ, y). Other works learn a generative neural network [16], [18] for more efficient sampling of the nontargeted UAPs. The generative network maps a random input to adversarial perturbation, inducing an implicit distribution on the set of UAPs. To obtain the UAPs for a target class t, SGD algorithm is run on a slightly different optimization problem given by, In our experiments, we generate m UAPs per target class by solving the optimization problem in (2). We do this efficiently for multiple target classes by learning a d×m|Y| dimensional embedding matrix W that maps a pair of target class t ∈ Y and an index k ∈ [m] to a vector in R d . For each minibatch, we choose the pair (t, k) and substitute h with the column of W corresponding to the pair (t, k). We iterate this process over several minibatches until a desired target classification rate is obtained.

LOCALLY OPTIMAL DETECTION
Denote the attacker A's perturbation distribution by ν(h). Further, denote the conditional perturbation distribution for a target class t by ν(h|t). Also, denote the adversarial input bỹ x = x + h, where the parameter 0 models the strength of the perturbation. The perturbed input conditioned on the target class t follows the distribution, The detection problem can be formulated as a binary hypothesis testing with composite H 1 : The detector is a decision rule δ : R d → {0, 1}, where δ(x) = 1 if the input x is declared adversarial and δ(x) = 0 otherwise. Using the Neyman-Pearson (NP) setup, optimal tests for maximizing P D ( ) = P 1 {δ(x) = 1} subject to a falsealarm constraint on the detector, P F = P 0 {δ(x) = 1} α, are Likelihood Ratio Tests (LRT) [19]. For small , LRT reduces to the locally optimal (LO) test. For the test in (3), the log-likelihood ratio (LLR) for each target class t ∈ Y is given by the following lemma: Lemma 1. Assume p 0 is twice continuously differentiable at x and ν(h|t) has exponential tails ∀t ∈ Y. Then the LLR, p0(x) , is given as: whereh t = H(t) hdν(h|t) is the mean perturbation for target class t. For multiple target classes, a popular choice is the generalized likelihood ratio test statistic (GLRT) given as, Thus, we can obtain the locally optimal GLRT statistic as, where τ is chosen to satisfy P F α. Intuitively, the LO-GLRT detector obtains the gradient of the data's log-density function i.e. ∇lnp 0 (x) at the received input, and computes its correlation with the (negative) mean perturbation vectors for each target class. The set of correlations is max-pooled to obtain the LO-GLRT test statistic.

Detection using constrained distributions
Learning a high dimensional input distribution is generally intractable. Hence, we consider a constrained probability distribution over the input. In particular, assume the input x can be subdivided into n independent subvectors x 1 , x 2 , · · · x n ∈ R d/n that are iid with common distribution q 0 . Then p 0 (x) = i q 0 (x i ). The perturbation h can likewise be divided into h 1 , · · · , h n where the subvectors h i need not be independent. Then, we obtain the LO-GLRT statistic as, For images in particular, we simplify the detector using the following constraints: (a) We implement the detector on grayscaled images instead of using all the three channels, (b) we divide the grayscaled-image into n tiles of size P × P each, where P is some factor of the full image size, and (c) we consider iid multivariate Gaussian distribution over the grayscaled-image tiles. In this case, the gradient over the i th tile would be given by, where Σ, µ denotes the covariance matrix and mean vector of the the Gaussian distribution respectively, and x i denotes the vectorized i th tile of the image x.

Learning the detector parameters
Under the prescribed constraints in section 3.1, the detector admits the parameters, θ = Σ, µ, h t t∈Y , τ . We learn the parameters in two stages: (a) Unsupervised pretraining: We use maximum likelihood estimation (MLE) to estimate the parameters µ, Σ of the multivariate Gaussian distributions. We use the empirical mean of the targeted perturbations to estimate h t t∈Y , (b) Supervised fine-tuning: We fine tune the parameters estimate from previous stage using supervised binary classification between unperturbed and perturbed images. Specifically, we obtain a set of N images, which contains unperturbed and perturbed images drawn with equal probability, and minimize the binary cross entropy loss given by, where y j = 0 if x j is unperturbed, y j = 1 for perturbed image x j , σ(.) denotes the sigmoid function and We reparametrize Σ = LL T to ensure that the matrix Σ remains positive semi-definite. We minimize the lossĤ(θ) using a minibatch SGD algorithm, with the parameter values initialized by their estimates from unsupervised pretraining.

Metric for attacker's performance
We now define a metric to quantify the net success rate of an adversarial perturbation. The success of the perturbations is controlled by two factors: Generally, using a small makes a perturbation undetectable but a sufficiently high is useful for fooling the classifier. For the attacker A using the perturbation distribution ν, we can define the probability of successful undetected attack as,

EXPERIMENTS
Setup: We evaluate the LO-GLRT detector for detection of UAPs for three popular image classification datasets: CIFAR10, CIFAR100 [20] and ImageNet validation set (ILSVRC 2012) [21]. The first two datasets contain 60,000 images of size 32×32, and are typically split into 50,000/10,000 for training/testing respectively. ILSVRC 2012 validation set contains 50,000 variable sized images that are resized into 224 × 224 for classification. We use 40,000 of the images for training and the rest 10,000 of the images for evaluation. The three datasets are divided into 10, 100 and 1000 classes respectively for classification. Each image consists of three channels {R,G,B}, and each pixel is quantized into 8 bits with pixel values ranging from 0 to 255. Attack generation: We generate 50 perturbations for each target class in CIFAR10, 10 perturbations in CIFAR100, and 2 perturbations for ImageNet using the method described in section 2. We used fewer perturbations for ImageNet due to high dimension of the images in dataset, which prohibits learning a large embedding matrix W . For CIFAR10 and CI-FAR100, we use ξ = 8, while for ImageNet we used ξ = 10 to bound the maximum ∞ -norm of the perturbations. Some sample UAPs for GoogleNet are shown in Figure 2.  [25] 0.968 0.963 0.5 Alexnet [4] 0.953 0.94 0.5 Table 1: Classification accuracy of several detectors on a dataset with unperturbed and perturbed images drawn by equal probability. The ∞ -norm of the perturbations is bound by 8 for CIFAR10/CIFAR100, and by 10 for ImageNet.
explains 95% of the data variance. Evaluation Metrics: We evaluate the detector using the following metrics: (1) classification accuracy on a sample of unperturbed images and adversarially perturbed images drawn with probability half each, (2) detection probability P D ( ) for varying perturbation strengths with α = 0.05, and (3) probability of successful undetected attack P su ( ). Note that = 1 corresponds to ξ = 8 for CIFAR10/CIFAR100 and ξ = 10 for ImageNet.

RESULTS
The classification accuracy of all the detectors is shown in the Table 1. We observe that PCA based detector fails to classify the diverse targeted adversarial perturbations accurately. Overall, LO-GLRT detector outperforms the PRN detector in classification accuracy. For P D ( ) and P su ( ), we compare LO-GLRT and PRN detectors only, since PCA based detector doesn't perform competitively. The plots for P D ( ) and P su ( ) of the two detectors is shown in Figure 3. Both the detectors achieve high detection probability for wide range of perturbation strengths, with LO-GLRT detector more robust to smaller perturbation strengths than PRN detector on ImageNet dataset. Further, P su ( ) of LO-GLRT detector is smaller, or at worst equal to the PRN detector.

CONCLUSION
In this paper, we derived the LO-GLRT for detection of random targeted UAPs added to the input of an image classifier. We also described a supervised training procedure for learning the detector's parameters. We observed high classification accuracy, high detection probability, and low probability of successful undetected attack, and showed better performance of the LO-GLRT detector relative to the PRN detector and superiority against PCA based detectors for three popular image classification datasets.