Certified Adversarial Robustness via Randomized Smoothing
Jeremy M Cohen, Elan Rosenfeld, J. Zico Kolter
Introduction
Modern image classifiers achieve high accuracy on i.i.d. test sets but are not robust to small, adversarially-chosen perturbations of their inputs (Szegedy et al., 2014; Biggio et al., 2013). Given an image correctly classified by, say, a neural network, an adversary can usually engineer an adversarial perturbation so small that looks just like to the human eye, yet the network classifies as a different, incorrect class. Many works have proposed heuristic methods for training classifiers intended to be robust to adversarial perturbations. However, most of these heuristics have been subsequently shown to fail against suitably powerful adversaries (Carlini & Wagner, 2017; Athalye et al., 2018; Uesato et al., 2018). In response, a line of work on certifiable robustness studies classifiers whose prediction at any point is verifiably constant within some set around (Wong & Kolter, 2018; Raghunathan et al., 2018a, e.g.). In most of these works, the robust classifier takes the form of a neural network. Unfortunately, all existing approaches for certifying the robustness of neural networks have trouble scaling to networks that are large and expressive enough to solve problems like ImageNet.
Randomized smoothing has one major drawback. If is a neural network, it is not possible to exactly compute the probabilities with which classifies as each class. Therefore, it is not possible to exactly evaluate ’s prediction at any input , or to exactly compute the radius in which this prediction is certifiably robust. Instead, we present Monte Carlo algorithms for both tasks that are guaranteed to succeed with arbitrarily high probability.
Despite this drawback, randomized smoothing enjoys several compelling advantages over other certifiably robust classifiers proposed in the literature: it makes no assumptions about the base classifier’s architecture, it is simple to implement and understand, and, most importantly, it permits the use of arbitrarily large neural networks as the base classifier. In contrast, other certified defenses do not currently scale to large networks. Indeed, smoothing is the only certified adversarial defense which has been shown feasible on the full-resolution ImageNet classification task.
Related Work
Many works have proposed classifiers intended to be robust to adversarial perturbations. These approaches can be broadly divided into empirical defenses, which empirically seem robust to known adversarial attacks, and certified defenses, which are provably robust to certain kinds of adversarial perturbations.
The most successful empirical defense to date is adversarial training (Goodfellow et al., 2015; Kurakin et al., 2017; Madry et al., 2018), in which adversarial examples are found during training (often using projected gradient descent) and added to the training set. Unfortunately, it is typically impossible to tell whether a prediction by an empirically robust classifier is truly robust to adversarial perturbations; the most that can be said is that a specific attack was unable to find any. In fact, many heuristic defenses proposed in the literature were later “broken” by stronger adversaries (Carlini & Wagner, 2017; Athalye et al., 2018; Uesato et al., 2018; Athalye & Carlini, 2018). Aiming to escape this cat-and-mouse game, a growing body of work has focused on defenses with formal guarantees.
Conservative certification is more scalable. Some conservative methods bound the global Lipschitz constant of the neural network (Gouk et al., 2018; Tsuzuku et al., 2018; Anil et al., 2019; Cisse et al., 2017), but these approaches tend to be very loose on expressive networks. Others measure the local smoothness of the network in the vicinity of a particular input . In theory, one could obtain a robustness guarantee via an upper bound on the local Lipschitz constant of the network (Hein & Andriushchenko, 2017), but computing this quantity is intractable for general neural networks. Instead, a panoply of practical solutions have been proposed in the literature (Wong & Kolter, 2018; Wang et al., 2018a, b; Raghunathan et al., 2018a, b; Wong et al., 2018; Dvijotham et al., 2018b, a; Croce et al., 2019; Gehr et al., 2018; Mirman et al., 2018; Singh et al., 2018; Gowal et al., 2018; Weng et al., 2018a; Zhang et al., 2018). Two themes stand out. Some approaches cast verification as an optimization problem and import tools such as relaxation and duality from the optimization literature to provide conservative guarantees (Wong & Kolter, 2018; Wong et al., 2018; Raghunathan et al., 2018a, b; Dvijotham et al., 2018b, a). Others step through the network layer by layer, maintaining at each layer an outer approximation of the set of activations reachable by a perturbed input (Mirman et al., 2018; Singh et al., 2018; Gowal et al., 2018; Weng et al., 2018a; Zhang et al., 2018). None of these local certification methods have been shown to be feasible on networks that are large and expressive enough to solve modern machine learning problems like the ImageNet classification task. Also, all either assume specific network architectures (e.g. ReLU activations or a layered feedforward structure) or require extensive customization for new network architectures.
Prior works have proposed using a network’s robustness to Gaussian noise as a proxy for its robustness to adversarial perturbations (Weng et al., 2018b; Ford et al., 2019), and have suggested that Gaussian data augmentation could supplement or replace adversarial training (Zantedeschi et al., 2017; Kannan et al., 2018). Smilkov et al. (2017) observed that averaging a classifier’s input gradients over Gaussian corruptions of an image yields very interpretable saliency maps. The robustness of neural networks to random noise has been analyzed both theoretically (Fawzi et al., 2016; Franceschi et al., 2018) and empirically (Dodge & Karam, 2017). Finally, Webb et al. (2019) proposed a statistical technique for estimating the noise robustness of a classifier more efficiently than naive Monte Carlo simulation; we did not use this technique since it appears to lack formal high-probability guarantees. While these works hypothesized relationships between a neural network’s robustness to random noise and the same network’s robustness to adversarial perturbations, randomized smoothing instead uses a classifier’s robustness to random noise to create a new classifier robust to adversarial perturbations.
Randomized smoothing
We will first present our robustness guarantee for the smoothed classifier . Then, since it is not possible to exactly evaluate the prediction of at or to certify the robustness of around , we will give Monte Carlo algorithms for both tasks that succeed with arbitrarily high probability.
Then for all , where
Theorem 1 assumes nothing about . This is crucial since it is unclear which well-behavedness assumptions, if any, are satisfied by modern deep architectures.
The certified radius is large when: (1) the noise level is high, (2) the probability of the top class is high, and (3) the probability of each other class is low.
Assume . For any perturbation with , there exists a base classifier consistent with the class probabilities (2) for which .
The complete proofs of Theorems 1 and 2 are in Appendix A. We now sketch the proofs in the special case when there are only two classes.
This “worst-case” classifies as with probability . Therefore, to ensure that even the “worst-case” classifies as with probability , we solve for those for which
which is equivalent to the condition . ∎
Theorem 2 is a simple consequence: for any with , the base classifier defined in (4) is consistent with (2); yet if is the base classifier, then .
2 Practical algorithms
We now present practical Monte Carlo algorithms for evaluating and certifying the robustness of around . More details can be found in Appendix C.
Evaluating the smoothed classifier’s prediction requires identifying the class with maximal weight in the categorical distribution . The procedure described in pseudocode as Predict draws samples of by running noise-corrupted copies of through the base classifier. Let be the class which appeared the largest number of times. If appeared much more often than any other class, then Predict returns . Otherwise, it abstains from making a prediction. We use the hypothesis test from Hung & Fithian (2019) to calibrate the abstention threshold so as to bound by the probability of returning an incorrect answer. Predict satisfies the following guarantee:
With probability at least over the randomness in Predict, Predict will either abstain or return . (Equivalently: the probability that Predict returns a class other than is at most .)
The function SampleUnderNoise(, , num, ) in the pseudocode draws num samples of noise, , runs each through the base classifier , and returns a vector of class counts. BinomPValue(, , ) returns the p-value of the two-sided hypothesis test that .
2.2 Certification
Evaluating and certifying the robustness of around an input requires not only identifying the class with maximal weight in , but also estimating a lower bound on the probability that and an upper bound on the probability that equals any other class. Doing all three of these at the same time in a statistically correct manner requires some care. One simple solution is presented in pseudocode as Certify: first, use a small number of samples from to take a guess at ; then use a larger number of samples to estimate ; then simply take .
With probability at least over the randomness in Certify, if Certify returns a class and a radius (i.e. does not abstain), then predicts within radius around : .
The function LowerConfBound(, , ) in the pseudocode returns a one-sided lower confidence interval for the Binomial parameter given a sample .
Recall from Theorem 1 that approaches as approaches 1. Unfortunately, it turns out that approaches 1 so slowly with that also approaches very slowly with . Consider the most favorable situation: everywhere. This means that is robust at radius . But after observing samples of which all equal , the tightest (to our knowledge) lower bound would say that with probability least , . Plugging and into (3) yields an expression for the certified radius as a function of : . Figure 5 (right) plots this function for . Observe that certifying a radius of with 99.9% confidence would require samples.
3 Training the base classifier
Theorem 1 holds regardless of how the base classifier is trained. However, in order for to classify the labeled example correctly and robustly, needs to consistently classify as . In high dimension, the Gaussian distribution places almost no mass near its mode . As a consequence, when is moderately high, the distribution of natural images has virtually disjoint support from the distribution of natural images corrupted by ; see Figure 2 for a visual demonstration. Therefore, if the base classifier is trained via standard supervised learning on the data distribution, it will see no noisy images during training, and hence will not necessarily learn to classify with ’s true label. Therefore, in this paper we follow Lecuyer et al. (2019) and train the base classifier with Gaussian data augmentation at variance . A justification for this procedure is provided in Appendix F. However, we suspect that there may be room to improve upon this training scheme, perhaps by training the base classifier so as to maximize the smoothed classifier’s certified accuracy at some tunable radius .
Experiments
In all experiments, unless otherwise stated, we ran Certify with , so there was at most a 0.1% chance that Certify returned a radius in which was not truly robust. Unless otherwise stated, when running Certify we used 100 Monte Carlo samples for selection and 100,000 samples for estimation.
In the figures above that plot certified accuracy as a function of radius , the certified accuracy always decreases gradually with until reaching some point where it plummets to zero. This drop occurs because for each noise level and number of samples , there is a hard upper limit to the radius we can certify with high probability, achieved when all samples are classified by as the same class.
Figure 6 plots the certified accuracy attained by smoothing with each . The dashed black line is the empirical upper bound on the robust accuracy of the base classifier architecture; observe that smoothing improves substantially upon the robustness of the undefended base classifier architecture. We see that controls a robustness/accuracy tradeoff. When is low, small radii can be certified with high accuracy, but large radii cannot be certified. When is high, larger radii can be certified, but smaller radii are certified at a lower accuracy. This observation echoes the finding in Tsipras et al. (2019) that adversarially trained networks with higher robust accuracy tend to have lower standard accuracy. Tables of these results are in Appendix E.
Figure 8 (left) plots the certified accuracy obtained using our Theorem 1 guarantee alongside the certified accuracy obtained using the analogous bounds of Lecuyer et al. (2019) and Li et al. (2018). Since our expression for the certified radius is greater (and, in fact, tight), our bound delivers higher certified accuracies. Figure 8 (middle) projects how the certified accuracy would have changed had Certify used more or fewer samples (under the assumption that the relative class proportions in counts would have remained constant). Finally, Figure 8 (right) plots the certified accuracy as the confidence parameter is varied. Observe that the certified accuracy is not very sensitive to .
In Figure 7, we compare the largest publicly released model from Wong et al. (2018), a small resnet, to two randomized smoothing classifiers: one which used the same small resnet architecture for its base classifier, and one which used a larger 110-layer resnet for its base classifier. First, observe that smoothing with the large 110-layer resnet substantially outperforms the baseline (across all hyperparameter settings) at all radii. Second, observe that smoothing with the small resnet also outperformed the method of Wong et al. (2018) at all but the smallest radii. We attribute this latter result to the fact that neural networks trained using the method of Wong et al. (2018) are “typically overregularized to the point that many filters/weights become identically zero,” per that paper. In contrast, the base classifier in randomized smoothing is a fully expressive neural network.
It is computationally expensive to certify the robustness of around a point , since the value of in Certify must be very large. However, it is far cheaper to evaluate at using Predict, since can be small. For example, when we ran Predict on ImageNet () using 100, making each prediction only took 0.15 seconds, and we attained a top-1 test accuracy of 65% (Appendix E).
As discussed earlier, an adversary can potentially force Predict to abstain with high probability. However, it is relatively rare for Predict to abstain on the actual data distribution. On ImageNet (), Predict with failure probability abstained 12% of the time when 100, 4% when 1000, and 1% when 10,000.
When is linear, there always exists a class-changing perturbation just beyond the certified radius. Since neural networks are not linear, we empirically assessed the tightness of our bound by subjecting an ImageNet smoothed classifier () to a projected gradient descent-style adversarial attack (Appendix J.3). For each example, we ran Certify with , and, if the example was correctly classified and certified robust at radius , we tried finding an adversarial example for within radius and within radius . We succeeded 17% of the time at radius and 53% of the time at radius .
Conclusion
Our strong empirical results suggest that randomized smoothing is a promising direction for future research into adversarially robust classification. Many empirical approaches have been “broken,” and provable approaches based on certifying neural network classifiers have not been shown to scale to networks of modern size. It seems to be computationally infeasible to reason in any sophisticated way about the decision boundaries of a large, expressive neural network. Randomized smoothing circumvents this problem: the smoothed classifier is not itself a neural network, though it leverages the discriminative ability of a neural network base classifier. To make the smoothed classifier robust, one need simply make the base classifier classify well under noise. In this way, randomized smoothing reduces the unsolved problem of adversarially robust classification to the comparably solved domain of supervised learning.
Acknowledgements
We thank Mateusz Kwaśnicki for help with Lemma 4 in the appendix, Aaditya Ramdas for pointing us toward the work of Hung & Fithian (2019), and Siva Balakrishnan for helpful discussions regarding the confidence interval in Appendix D. We thank Tolani Olarinre, Adarsh Prasad, Ben Cousins, Ramon Van Handel, Matthias Lecuyer, and Bai Li for useful conversations. Finally, we are very grateful to Vaishnavh Nagarajan, Arun Sai Suggala, Shaojie Bai, Mikhail Khodak, Han Zhao, and Zachary Lipton for reviewing drafts of this work. Jeremy Cohen is supported by a grant from the Bosch Center for AI.
References
Appendix A Proofs of Theorems 1 and 2
Here we provide the complete proofs for Theorem 1 and Theorem 2. We fist prove the following lemma, which is essentially a restatement of the Neyman-Pearson lemma (Neyman & Pearson, 1933) from statistical hypothesis testing.
Without loss of generality, we assume that is random and write for the probability that .
First we prove part 1. We denote the complement of as .
The inequality in the middle is due to the fact that and . The inequality at the end is because both terms in the product are non-negative by assumption.
The proof for part 2 is virtually identical, except both “” become “.” ∎
Now we state the special case of Lemma 3 for when and are isotropic Gaussians.
This lemma is the special case of Lemma 3 when and are isotropic Gaussians with means and .
By Lemma 3 it suffices to simply show that for any , there is some for which:
The likelihood ratio for this choice of and turns out to be:
where and are constants w.r.t , specifically and .
Therefore, given any we may take , noticing that
Finally, we prove Theorem 1 and Theorem 2.
Then for all , where
To show that , it follows from the definition of that we need to show that
We now restate and prove Theorem 2, which shows that the bound in Theorem 1 is tight. The assumption below in Theorem 2 that is mild: given any and which do not satisfy this condition, one could have always redefined to obtain a Theorem 1 guarantee with a larger certified radius, so there is no reason to invoke Theorem 1 unless .
We re-use notation from the preceding proof.
Pick any class arbitrarily. Define and as above, and consider the function
This function is well-defined, since provided that .
By construction, the function satisfies (6) with equalities, since
Therefore, if is the base classifier for , then . ∎
A.0.1 Deferred Algebra
Recall that and .
Recall that and .
Recall that and .
Recall that and .
Appendix B Smoothing a two-class linear classifier
In this appendix, we analyze what happens when the base classifier is a two-class linear classifier . To match the definition of , we take to be undefined when its argument is zero.
Our first result is that when is a two-class linear classifier, the smoothed classifier is identical to the base classifier .
If is a two-class linear classifier , and is the smoothed version of with any , then for any (where is defined).
A similar calculation shows that .
If is a two-class linear classifier , and is the smoothed version of with any , then invoking Theorem 1 at any (where is defined) with and will yield the certified radius .
In binary classification, , so Theorem 1 returns .
There are two cases: if , then
Therefore, the bound in Theorem 1 returns a radius of
The previous two propositions imply that when is a two-class linear classifier, the Theorem 1 bound is “tight” in the sense that there always exists a class-changing perturbation just beyond the certified radius.Note that this is a different sense of “tight” than the sense in which Theorem 2 proves that Theorem 1 is tight. Theorem 2 proves that for any fixed perturbation outside the radius certified by Theorem 1, there exists a base classifier for which . In contrast, Proposition 5 proves that for any fixed binary linear base classifier , there exists a perturbation just outside the radius certified by Theorem 1 for which .
Let be a two-class linear classifier , let be the smoothed version of for some , let be any point (where is defined), and let be the radius certified around by Theorem 1. Then for any radius , there exists a perturbation with for which .
By Proposition 3 it suffices to show that there exists some perturbation with for which .
By Proposition 4, we know that .
If , consider the perturbation . This perturbation satisfies and
Likewise, if , then consider the perturbation . This perturbation satisfies and .
This special property of two-class linear classifiers is not true in general. In fact, it is possible to construct situations where ’s prediction around some point is robust at radius , yet Theorem 1 only certifies a radius of , where is arbitrarily close to zero.
For any , there exists a base classifier and an input for which the corresponding smoothed classifier is robust around at radius , yet Theorem 1 only certifies a radius of around .
Let and consider the following base classifier:
Let be the smoothed version of with . We will show that everywhere, implying that ’s prediction is robust around with radius . Yet Theorem 1 only certifies a radius of around .
Let . For any , we have:
so by Theorem 1, the certified radius around is .
The proof of Proposition 6 employed the following lemma, which formalizes the visually obvious fact that out of all intervals of some fixed width , the interval with maximal mass under the standard normal distribution is the interval .
Let be the PDF of the standard normal distribution. Since is symmetric about the origin (i.e. ),
where the inequality is because is monotonically decreasing on .
Note that by construction, , and and .
where the inequality is again because is monotonically decreasing on . ∎
Appendix C Practical algorithms
In this appendix, we elaborate on the prediction and certification algorithms described in Section 3.2. The pseudocode in Section 3.2 makes use of several helper functions:
SampleUnderNoise(, , num, ) works as follows:
Draw num samples of noise, .
Run the noisy images through the base classifier to obtain the predictions .
Return the counts for each class, where the count for class is defined as .
BinomPValue(, , ) returns the p-value of the two-sided hypothesis test that . Using scipy.stats.binom_test, this can be implemented as: binom_test(nA, nA + nB, p).
LowerConfBound(, , ) returns a one-sided lower confidence interval for the Binomial parameter given that . In other words, it returns some number for which with probability at least over the sampling of . Following Lecuyer et al. (2019), we chose to use the Clopper-Pearson confidence interval, which inverts the Binomial CDF (Clopper & Pearson, 1934). Using statsmodels.stats.proportion.proportion_confint, this can be implemented as
The randomized algorithm given in pseudocode as Predict leverages the hypothesis test given in Hung & Fithian (2019) for identifying the top category of a multinomial distribution. Predict has one tunable hyperparameter, . When is small, Predict abstains frequently but rarely returns the wrong class. When is large, Predict usually makes a prediction, but may often return the wrong class.
We now prove that with high probability, Predict will either return or abstain.
Proposition 1 (restated). With probability at least over the randomness in Predict, Predict will either abstain or return . (Equivalently: the probability that Predict returns a class other than is at most .)
We can describe the randomized procedure Predict as follows:
Sample a vector of class counts from .
Let be the class whose count is largest. Let and be the largest count and the second-largest count, respectively.
If the p-value of the two-sided hypothesis test that is drawn from is less than , then return . Else, abstain.
The quantities and the ’s are fixed but unknown, while the quantities , the ’s, , and are random.
We’d like to prove that the probability that Predict returns a class other than is at most . Predict returns a class other than if and only if (1) and (2) Predict does not abstain.
Recall that Predict does not abstain if and only if the p-value of the two-sided hypothesis test that is drawn from is less than . Theorem 1 in Hung & Fithian (2019) proves that the conditional probability that this event occurs given that is exactly . That is,
C.2 Certification
Suppose for simplicity that we already knew and needed to obtain . We could collect samples of , count how many times , and use a Binomial confidence interval to obtain a lower bound on that holds with probability at least over the samples.
However, estimating and while simultaneously identifying the top class is a little bit tricky, statistically speaking. We propose a simple two-step procedure. First, use samples from to take a guess at the identity of the top class . In practice we observed that tends to put most of its weight on the top class, so can be set very small. Second, use samples from to obtain some and for which and with probability at least . We observed that it is much more typical for the mass of not allocated to to be allocated entirely to one runner-up class than to be allocated uniformly over all remaining classes. Therefore, the quantity is a reasonably tight upper bound on . Hence, we simply set , so our bound becomes
The full procedure is described in pseudocode as Certify. If , we abstain from making a certification; this can occur especially if , i.e. if we misidentify the top class using the first samples of .
Proposition 2 (restated). With probability at least over the randomness in Certify, if Certify returns a class and a radius (i.e. does not abstain), then we have the robustness guarantee
Appendix D Estimating the certified test-set accuracy
In this appendix, we show how to convert the “approximate certified test accuracy” considered in the main paper into a lower bound on the true certified test accuracy that holds with high probability over the randomness in Certify.
Consider a classifier , a test set , and a radius . For each example , let indicate whether ’s prediction at is both correct and robust at radius , i.e.
For any , with probability at least over the randomness in Certify,
Let and be the number of test examples on which or , respectively. We model , where is in general unknown. Let and . The quantity of interest, the certified accuracy , is equal to . However, we only observe .
From now on, we manipulate this inequality — remember that it holds with probability at least .
Since , may write
Since , we may write
Since , we may write
Finally, in order to make this confidence interval depend only on observables, we use to write
Dividing both sides of the inequality by recovers the theorem statement.
Appendix E ImageNet and CIFAR-10 Results
Tables 2 and 3 show the approximate certified top-1 test set accuracy of randomized smoothing on ImageNet and CIFAR-10 with various noise levels . By “approximate certified accuracy,” we mean that we ran Certify on a subsample of the test set, and for each we report the fraction of examples on which Certify (a) did not abstain, (b) returned the correct class, and (c) returned a radius greater than . There is some probability (at most ) that any example’s certification is inaccurate. We used and . On CIFAR-10 our base classifier was a 110-layer residual network and we certified the full test set; on ImageNet our base classifier was a ResNet-50 and we certified a subsample of 500 points. Note that the certified accuracy at is just the standard accuracy of the smoothed classifier. See Appendix J for more experimental details.
E.2 Prediction
Table 4 shows the performance of Predict as the number of Monte Carlo samples is varied between 100 and 10,000. Suppose that for some test example , Predict returns the label . We say that this prediction was correct if and we say that this prediction was accurate if . For example, a prediction could be correct but inaccurate if is wrong at , yet Predict accidentally returns the correct class. Ideally, we’d like Predict to be both correct and accurate.
With 100 Monte Carlo samples and a failure rate of , Predict is cheap to evaluate (0.15 seconds on our hardware) yet it attains relatively high top-1 accuracy of 65% on the ImageNet test set, and only abstains 12% of the time. When we use 10,000 Monte Carlo samples, Predict takes longer to evaluate (15 seconds), yet only abstains 4% of the time. Interestingly, we observe from Table 4 that most of the abstentions when were for examples on which was wrong, so in practice we would lose little accuracy by taking to be as small as 100.
Appendix F Training with Noise
As mentioned in section 3.3, in the experiments for this paper, we followed Lecuyer et al. (2019) and trained the base classifier by minimizing the cross-entropy loss with Gaussian data augmentation. We now provide some justification for this idea.
Let be a training dataset. We assume that the base classifier takes the form , where each is the scoring function for class .
Suppose that our goal is to maximize the sum of of the log-probabilities that will classify each as :
Recall that the softmax function can be interpreted as a continuous, differentiable approximation to :
Therefore, our objective is approximately equal to:
By Jensen’s inequality and the concavity of , this quantity is lower-bounded by:
which is the negative of the cross-entropy loss under Gaussian data augmentation.
Therefore, minimizing the cross-entropy loss under Gaussian data augmentation will maximize (18), which will approximately maximize (17).
Appendix G Noise Level can Scale with Input Resolution
The argument above can be made rigorous, though we first need to decide what it means for two images to be high- and low-resolution versions of each other. Here we present one solution:
Let denote the space of “high-resolution” images in dimension , and let denote the space of “low-resolution” images in dimension . Let be the function which takes as input an image in dimension , averages together every 2x2 square of pixels, and outputs an image in dimension .
Equipped with these definitions, we can say that are a high/low resolution image pair if .
Given any smoothing classifier , one can construct a smoothing classifier with the following property: for any and , predicts the same class at that predicts at , but is certifiably robust at twice the radius.
Given some smoothing classifier from to , define to be the smoothing classifier from to with noise level and base classifier . Note that the average of four independent copies of is distributed as . Therefore, for any high/low-resolution image pair , the random variable , where , is equal in distribution to the random variable , where . Hence, has the same distribution as . By the definition of , this means that , Additionally, by Theorem 1, since , this means that ’s prediction at is certifiably robust at twice the radius as ’s prediction at . ∎
Appendix H Additional Experiments
H.2 High-probability guarantees
Appendix D details how to use Certify to obtain a lower bound on the certified test accuracy at radius of a randomized smoothing classifier that holds with high probability over the randomness in Certify. In the main paper, we declined to do this and simply reported the approximate certified test accuracy, defined as the fraction of test examples for which Certify gives the correct prediction and certifies it at radius . Of course, with some probability (guaranteed to be less than ), each of these certifications is wrong.
However, we now demonstrate empirically that there is a negligible difference between a proper high-probability lower bound on the certified accuracy and the approximate version that we reported in the paper. We created a randomized smoothing classifier on ImageNet with a ResNet-50 base classifier and noise level . We used Certify with to certify a subsample of 500 examples from the ImageNet test set. From this we computed the approximate certified test accuracy at each radius . Then we used the correction from Appendix D with to obtain a lower bound on the certified test accuracy at that holds pointwise with probability at least over the randomness in Certify. Figure 14 plots both quantities as a function of . Observe that the difference is so negligible that the lines almost overlap.
H.3 How much noise to use when training the base classifier?
In the main paper, whenever we created a randomized smoothing classifier at noise level , we always trained the corresponding base classifier with Gaussian data augmentation at noise level . In Figure 15, we show the effects of training the base classifier with a different level of Gaussian noise. Observe that has a lower certified accuracy if was trained using a different noise level. It seems to be worse to train with noise than to train with noise .
Appendix I Derivation of Prior Randomized Smoothing Guarantees
In this appendix, we derive the randomized smoothing guarantees of Lecuyer et al. (2019) and Li et al. (2018) using the notation of our paper. Both guarantees take same general form as ours, except with a different expression for :
Then for all .
For convenience, define the notation and .
Lecuyer et al. (2019) proved a version of the generic robustness guarantee in which
In order to avoid notation that conflicts with the rest of this paper, we use and where Lecuyer et al. (2019) used and .
Suppose that we have some and such that
The “Gaussian mechanism” from differential privacy guarantees that:
See Lecuyer et al. (2019), Lemma 2 for how to obtain this form from the standard form of the DP definition.
Since the RHS is always positive, and the denominator on the LHS is always positive, this condition can only possibly hold if the numerator on the LHS is positive. Therefore, we need to restrict to
Since and , the denominator in the LHS is which is in turn the numerator on the LHS. Therefore, the term inside the log in the LHS is greater than 1, so the log term on the LHS is greater than zero. Therefore, we may divide both sides of the inequality by the log term on the LHS to obtain:
Finally, we take the square root and maximize the bound over all valid (28) to yield:
Figure 16(a) plots this bound at varying settings of the tuning parameter , while Figure 16(c) plots how the bound varies with for a fixed and .
I.2 Li et al. (2018)
Li et al. (2018) proved a version of the generic robustness guarantee in which
A generalization of KL divergence, the -Renyi divergence is an information theoretic measure of distance between two distributions. It is parameterized by some . The -Renyi divergence between two discrete distributions and is defined as:
In the continuous case, this sum is replaced with an integral. The divergence is undefined when since a division by zero occurs, but the limit of as is the KL divergence between and .
Li et al. (2018) prove that if is a discrete distribution for which the highest probability class has probability and all other classes have probability , then for any other discrete distribution for which
the highest-probability class in is guaranteed to be the same as the highest-probability class in .
We now apply this result to the discrete distributions and . If satisfies (33), then it is guaranteed that .
The data processing inequality states that applying a function to two random variables can only decrease the -Renyi divergence between them. In particular,
There is a closed-form expression for the -Renyi divergence between two Gaussians:
Therefore, we can guarantee that so long as
Finally, since this result holds for any , we may maximize over to obtain the largest possible certified radius:
Figure 16(b) plots this bound at varying settings of the tuning parameter , while figure 16(d) plots how the bound varies with for a fixed and .
Appendix J Experiment Details
In image classification it is common practice to preprocess a dataset by subtracting from each channel the mean over the dataset, and dividing each channel by the standard deviation over the dataset. However, we wanted to report certified radii in the original image coordinates rather than in the standardized coordinates. Therefore, throughout most of this work we first added the Gaussian noise, and then standardized the channels, before feeding the image to the base classifier. (In the practical PyTorch implementation, the first layer of the base classifier was a layer that standardized the input.) However, all of the baselines we compared against provided pre-trained networks which assumed that the dataset was first preprocessed in a specific way. Therefore, when comparing against the baselines we also preprocessed the datasets first, so that we could report certified radii that were directly comparable to the radii reported by the baseline methods.
Following Wong et al. (2018), the CIFAR-10 dataset was preprocessed by subtracting and dividing by .
For randomized smoothing we used and a 20-layer residual network base classifier. We ran Certify with , 100,000 and .
For both methods, we certified the full CIFAR-10 test set.
Following Tsuzuku et al. (2018), the SVHN dataset was not preprocessed except that pixels were divided by 255 so as to lie within .
We compared against a pretrained network provided to us by the authors in which the hyperparameter of their method was set to . The network was a wide residual network with 16 layers and a width factor of 4. We used the authors’ code at https://github.com/ytsmiling/lmt to compute the robustness radius of test images.
For randomized smoothing we used and a 20-layer residual network base classifier. We ran Certify with , 100,000 and .
For both methods, we certified the whole SVHN test set.
Following Zhang et al. (2018), the CIFAR-10 dataset was preprocessed by subtracting 0.5 from each pixel.
We compared against the cifar_7_1024_vanilla network released by the authors, which is a 7-layer MLP. We used the authors’ code at https://github.com/IBM/CROWN-Robustness-Certification to compute the robustness radius of test images.
For randomized smoothing we used and a 20-layer residual network base classifier. We ran Certify with , 100,000 and .
For randomized smoothing, we certified the whole CIFAR-10 test set. For Zhang et al. (2018), we certified every fourth image in the CIFAR-10 test set.
J.2 ImageNet and CIFAR-10 Experiments
Our code is available at http://github.com/locuslab/smoothing.
In order to report certified radii in the original coordinates, we first added Gaussian noise, and then standardized the data. Specifically, in our PyTorch implementation, the first layer of the base classifier was a normalization layer that performed a channel-wise standardization of its input. For CIFAR-10 we subtracted the dataset mean and divided by the dataset standard deviation . For ImageNet we subtracted the dataset mean and divided by the standard deviation .
For both ImageNet and CIFAR-10, we trained the base classifier with random horizontal flips and random crops (in addition to the Gaussian data augmentation discussed explicitly in the paper). On ImageNet we trained with synchronous SGD on four NVIDIA RTX 2080 Ti GPUs; training took approximately three days.
On ImageNet our base classifier used the ResNet-50 architecture provided in torchvision. On CIFAR-10 we used a 110-layer residual network from https://github.com/bearpaw/pytorch-classification.
On ImageNet we certified every 100-th image in the validation set, for 500 images total. On CIFAR-10 we certified the whole test set.
In Figure 8 (middle) we fixed and while varying the number of samples . We did not actually vary the number of samples that we simulated: we kept this number fixed at 100,000 but varied the number that we fed the Clopper-Pearson confidence interval.
In Figure 8 (right), we fixed and 100,000 while varying .
J.3 Adversarial Attacks
As discussed in Section 4, we subjected smoothed classifiers to a projected gradient descent-style adversarial attack. We now describe the details of this attack.
In practice, our step size was , we used steps of PGD, and we computed the stochastic gradient using Monte Carlo samples.
Unfortunately, the objective we optimize (39) is not actually the attack objective of interest. To force a misclassification, an attacker needs to find some perturbation with and some class for which
Effective adversarial attacks against randomized smoothing are outside the scope of this paper.
Appendix K Examples of Noisy Images
We now show examples of CIFAR-10 and ImageNet images corrupted with varying levels of noise.