MACER: A TTACK - FREE AND S CALABLE R OBUST T RAINING VIA M AXIMIZING C ERTIFIED R ADIUS
A BSTRACT
Adversarial training is one of the most popular ways to learn robust models but is usually attack-dependent and time costly.
In this paper, we propose the MACER algorithm, which learns robust models without using adversarial training but per- forms better than all existing provable l 2 -defenses.
Recent work (Cohen et al., 2019) shows that randomized smoothing can be used to provide a certiﬁed l 2 ra- dius to smoothed classiﬁers, and our algorithm trains provably robust smoothed classiﬁers via MAximizing the CErtiﬁed Radius (MACER).
The attack-free char- acteristic makes MACER faster to train and easier to optimize.
In our experiments, we show that our method can be applied to modern deep neural networks on a wide range of datasets, including Cifar-10, ImageNet, MNIST, and SVHN.
For all tasks, MACER spends less training time than state-of-the-art adversarial training algorithms, and the learned models achieve larger average certiﬁed radii.
Our code is available at https://github.com/RuntianZ/macer .
I NTRODUCTION
Modern neural network classiﬁers are able to achieve very high accuracy on image classiﬁcation tasks but are sensitive to small, adversarially chosen perturbations to the inputs (Szegedy et al., 2013;
Biggio et al., 2013).
Given an image x that is correctly classiﬁed by a neural network, a malicious attacker may ﬁnd a small adversarial perturbation δ such that the perturbed image x + δ , though visually indistinguishable from the original image, is assigned to a wrong class with high conﬁdence by the network.
Such vulnerability creates security concerns in many real-world applications.
Researchers have proposed a variety of defense methods to improve the robustness of neural networks.
Most of the existing defenses are based on adversarial training (Szegedy et al., 2013; Madry et al., 2017; Goodfellow et al., 2015; Huang et al., 2015; Athalye et al., 2018; Ding et al., 2020).
During training, these methods ﬁrst learn on-the-ﬂy adversarial examples of the inputs with multiple attack iterations and then update model parameters using these perturbed samples together with the original labels.
However, such approaches depend on a particular (class of) attack method.
It cannot be formally guaranteed whether the resulting model is also robust against other attacks.
Moreover, attack iterations are usually quite expensive.
As a result, adversarial training runs very slowly.
Another line of algorithms trains robust models by maximizing the certiﬁed radius provided by robust certiﬁcation methods (Weng et al., 2018; Wong & Kolter, 2018;
Zhang et al., 2018; Mirman et al., 2018; Wang et al., 2018; Gowal et al., 2018; Zhang et al., 2019c).
Using linear or convex relaxations of fully connected ReLU networks, a robust certiﬁcation method computes a “safe radius” r for a classiﬁer at a given input such that at any point within the neighboring radius- r ball of the input, the classiﬁer is guaranteed to have unchanged predictions.
However, the certiﬁcation methods are usually computationally expensive and can only handle shallow neural networks with
ReLU activations, so these training algorithms have troubles in scaling to modern networks.
In this work, we propose an attack-free and scalable method to train robust deep neural networks.
We mainly leverage the recent randomized smoothing technique (Cohen et al., 2019).
A randomized smoothed classiﬁer g for an arbitrary classiﬁer f is deﬁned as g ( x ) =
E η f ( x + η ) , in which η ∼
N (0 , σ 2 I ) .
While Cohen et al.
(2019) derived how to analytically compute the certiﬁed radius of the randomly smoothed classiﬁer g , they did not show how to maximize that radius to make the classiﬁer g robust.
Salman et al.
(2019) proposed SmoothAdv to improve the robustness of g , but it still relies on the expensive attack iterations.
Instead of adversarial training, we propose to learn robust models by directly taking the certiﬁed radius into the objective.
We outline a few challenging desiderata any practical instantiation of this idea would however have to satisfy, and provide approaches to address each of these in turn.
A discussion of these desiderata, as well as a detailed implementation of our approach is provided in Section 4.
And as we show both theoretically and empirically, our method is numerically stable and accounts for both classiﬁcation accuracy and robustness.
Our contributions are summarized as follows:
• We propose an attack-free and scalable robust training algorithm by MAximizing the CErtiﬁed Radius (MACER).
MACER has the following advantages compared to previous works: – Different from adversarial training, we train robust models by directly maximizing the certiﬁed radius without specifying any attack strategies, and the learned model can achieve provable robustness against any possible attack in the certiﬁed region.
Additionally, by avoiding time-consuming attack iterations, our proposed algorithm runs much faster than adversarial training.
– Different from other methods (Wong & Kolter, 2018) that maximize the certiﬁed radius but are not scalable to deep neural networks, our method can be applied to architectures of any size.
This makes our algorithm more practical in real scenarios.
• We empirically evaluate our proposed method through extensive experiments on Cifar-10, ImageNet, MNIST, and SVHN.
On all tasks, MACER achieves better performance than state-of-the-art algorithms.
MACER is also exceptionally fast.
For example, on ImageNet, MACER uses 39% less training time than adversarial training but still performs better.
R ELATED WORK
Neural networks trained by standard SGD are not robust – a small and human imperceptible perturbation can easily change the prediction of a network.
In the white-box setting, methods have been proposed to construct adversarial examples with small (cid:96) ∞ or (cid:96) 2 perturbations (Goodfellow et al., 2015; Madry et al., 2017; Carlini & Wagner, 2016; Moosavi-Dezfooli et al., 2015).
Furthermore, even in the black-box setting where the adversary does not have access to the model structure and parameters, adversarial examples can be found by either transfer attack (Papernot et al., 2016) or optimization-based approaches (Chen et al., 2017; Rauber et al., 2017; Cheng et al., 2019).
It is thus important to study how to improve the robustness of neural networks against adversarial examples.
Adversarial training
So far, adversarial training has been the most successful robust training method according to many recent studies.
Adversarial training was ﬁrst proposed in Szegedy et al.
(2013) and Goodfellow et al.
(2015), where they showed that adding adversarial examples to the training set can improve the robustness against such attacks.
More recently, Madry et al.
(2017) formulated adversarial training as a min-max optimization problem and demonstrated that adversarial training with PGD attack leads to empirical robust models.
Zhang et al.
(2019b) further decomposed the robust error as the sum of natural error and boundary error for better performance.
Finally, Gao et al.
(2019) proved the convergence of adversarial training.
Although models obtained by adversarial training empirically achieve good performance, they do not have certiﬁed error guarantees.
Despite the popularity of PGD-based adversarial training, one major issue is that its speed is too slow.
Some recent papers propose methods to accelerate adversarial training.
For example, Freem (Shafahi et al., 2019) replays an adversarial example several times in one iteration, YOPO-m-n (Zhang et al., 2019a) restricts back propagation in PGD within the ﬁrst layer, and Qin et al.
(2019) estimates the adversary with local linearization.
Robustness certiﬁcation and provable defense
Many defense algorithms proposed in the past few years were claimed to be effective, but Athalye et al.
(2018) showed that most of them are based on “gradient masking” and can be bypassed by more carefully designed attacks.
It is thus important to study how to measure the provable robustness of a network.
A robustness certiﬁcation algorithm takes a classiﬁer f and an input point x as inputs, and outputs a “safe radius” r such that for any δ subject to (cid:107) δ (cid:107) ≤ r , f ( x ) =
f ( x + δ ) .
Several algorithms have been proposed recently, including the convex polytope technique (Wong & Kolter, 2018), abstract interpretation methods (Singh et al., 2018;
Gehr et al., 2018) and the recursive propagation algrithms (Weng et al., 2018; Zhang et al.,
These methods can provide attack-agnostic robust error lower bounds.
Moreover, to achieve networks with nontrivial certiﬁed robust error , one can train a network by minimizing the certiﬁed robust error computed by the above-mentioned methods, and several algorithms have been proposed in the past year (Wong & Kolter, 2018;
Wong et al., 2018; Wang et al., 2018; Gowal et al., 2018;
Zhang et al., 2019c; Mirman et al., 2018).
Unfortunately, they can only be applied to shallow networks with limited activation and run very slowly.
More recently, researchers found a new class of certiﬁcation methods called randomized smoothing.
The idea of randomization has been used for defense in several previous works (Xie et al., 2017;
Liu et al., 2018)
but without any certiﬁcation.
Later on, Lecuyer et al.
ﬁrst showed that if a Gaussian random noise is added to the input or any intermediate layer.
A certiﬁed guarantee on small (cid:96) 2 perturbation can be computed via differential privacy.
Li et al.
and Cohen et al.
(2019) then provided improved ways to compute the (cid:96) 2 certiﬁed robust error for Gaussian smoothed models.
In this paper, we propose a new algorithm to train on these (cid:96) 2 certiﬁed error bounds to signiﬁcantly reduce the certiﬁed error and achieve better provable adversarial robustness.
P RELIMINARIES
Problem setup Consider a standard classiﬁcation task with an underlying data distribution p data over pairs of examples x ∈ X ⊂ R d and corresponding labels y ∈ Y
= { 1 , 2 , · · · , K } .
Usually p data is unknown and we can only access a training set S
= { ( x 1 , y 1 ) , · · · , ( x n , y n ) } in which ( x i , y i ) is i.i.d.
drawn from p data , i = 1 , 2 , · · · , n .
The empirical data distribution (uniform distribution over S ) is denoted by ˆ p data .
Let f ∈ F be the classiﬁer of interest that maps any x ∈ X to
Y .
Usually f is parameterized by a set of parameters θ , so we also write it as f θ .
We call x (cid:48)
=
x + δ an adversarial example of x to classiﬁer f
θ if f θ can correctly classify x but assigns a different label to x (cid:48) .
Following many previous works (Cohen et al., 2019; Salman et al., 2019), we focus on the setting where δ satisﬁes (cid:96) 2 norm constraint (cid:107) δ (cid:107) 2 ≤ (cid:15) .
We say that the model f θ is l (cid:15) 2 - robust at ( x, y ) if it correctly classiﬁes x as y and for any (cid:107) δ (cid:107) 2 ≤ (cid:15) , the model classiﬁes x + δ as y .
In the problem of robust classiﬁcation, our ultimate goal is to ﬁnd a model that is l (cid:15)
2 -robust at ( x, y ) with high probability over ( x, y ) ∼ p data for a given (cid:15) > 0 .
Neural network In image classiﬁcation we often use deep neural networks.
Let u θ : X → R K be a neural network, whose output at input x is a vector ( u 1 θ ( x ) , ..., u Kθ ( x )) .
The classiﬁer induced by u θ ( x ) is f θ ( x ) =
arg max c ∈Y u cθ ( x ) .
In order to train θ by minimizing a loss function such as cross entropy, we always use a softmax layer on u θ to normalize it into a probability distribution.
The resulting network is z θ ( · ; β ) :
X → P ( K ) 1 , which is given by z cθ ( x ; β ) =
e βu cθ ( x ) / (cid:80) c (cid:48) ∈Y e βu c (cid:48)
θ ( x ) , ∀ c ∈ Y , β is the inverse temperature.
For simplicity, we will use z θ ( x ) to refer to z θ ( x ; β ) when the meaning is clear from context.
The vector z θ ( x ) = ( z 1 θ ( x ) , · · · , z Kθ ( x )) is commonly regarded as the “likelihood vector”, and z cθ ( x ) measures how likely input x belongs to class c .
Robust radius By deﬁnition, the l (cid:15) 2 -robustness of f θ at a data point ( x, y ) depends on the radius of the largest l 2 ball centered at x in which f θ does not change its prediction.
This radius is called the robust radius , which is formally deﬁned as
[Equation]
Recall that our ultimate goal is to train a classiﬁer which is l (cid:15) 2 -robust at ( x, y ) with high probability over the sampling of ( x, y ) ∼ p data .
Mathematically the goal can be expressed as to minimize the expectation of the 0/1 robust classiﬁcation error .
The error is deﬁned as
[Equation]
and the goal is to minimize its expectation over the population
[Equation]
It is thus quite natural to improve model robustness via maximizing the robust radius.
Unfortunately, computing the robust radius (1) of a classiﬁer induced by a deep neural network is very difﬁcult.
Weng et al.
(2018) showed that computing the l 1 robust radius of a deep neural network is NP-hard.
Although there is no result for the l 2 radius yet, it is very likely that computing the l 2 robust radius is also NP-hard.
Certiﬁed radius Many previous works proposed certiﬁcation methods that seek to derive a tight lower bound of R ( f θ ; x, y ) for neural networks (see Section 2 for related work).
We call this lower bound certiﬁed radius and denote it by CR ( f θ ; x, y ) .
The certiﬁed radius satisﬁes 0 ≤ CR ( f θ ; x, y ) ≤ R ( f θ ; x, y ) for any f θ , x, y .
The certiﬁed radius leads to a guaranteed upper bound of the 0/1 robust classiﬁcation error, which is called 0/1 certiﬁed robust error .
The 0/1 certiﬁed robust error of classiﬁer f θ on sample ( x, y ) is deﬁned as
[Equation]
i.e. a sample is counted as correct only if the certiﬁed radius reaches (cid:15) .
The expectation of certiﬁed robust error over ( x, y ) ∼ p data serves as a performance metric of the provable robustness:
[Equation]
Recall that CR ( f θ ; x, y ) is a lower bound of the true robust radius, which immediately implies that
[Equation]
− robust ( f θ ) .
Therefore, a small 0/1 certiﬁed robust error leads to a small 0/ robust classiﬁcation error.
Randomized smoothing In this work, we use the recent randomized smoothing technique (Cohen et al., 2019), which is scalable to any architectures, to obtain the certiﬁed radius of smoothed deep neural networks.
The key part of randomized smoothing is to use the smoothed version of f θ , which is denoted by g θ , to make predictions.
The formulation of g θ is deﬁned as follows.
Deﬁnition 1.
For an arbitrary classiﬁer f θ ∈ F and σ > 0 , the smoothed classiﬁer g θ of f θ is deﬁned as
[Equation]
In short, the smoothed classiﬁer g θ ( x ) returns the label most likely to be returned by f θ when its input is sampled from a Gaussian distribution N ( x, σ 2 I ) centered at x .
Cohen et al.
(2019) proves the following theorem, which provides an analytic form of certiﬁed radius:
Theorem 1.
(Cohen et al., 2019)
Let f θ ∈ F , and η ∼ N (0 , σ 2 I ) .
Let the smoothed classiﬁer g θ be deﬁned as in (6).
Let the ground truth of an input x be y .
If g θ classiﬁes x correctly, i.e.
[Equation]
Then g θ is provably robust at x , with the certiﬁed radius given by
[Equation]
where Φ is the c.d.f.
of the standard Gaussian distribution.
R OBUST TRAINING VIA MAXIMIZING THE CERTIFIED RADIUS
As we can see from Theorem 1, the value of the certiﬁed radius can be estimated by repeatedly sampling Gaussian noises.
More importantly, it can be computed for any deep neural networks.
This motivates us to design a training method to maximize the certiﬁed radius and learn robust models.
To minimize the 0/1 robust classiﬁcation error in (3) or the 0/1 certiﬁed robust error in (5), many previous works (Zhang et al., 2019b; Zhai et al., 2019) proposed to ﬁrst decompose the error.
Note that a classiﬁer g θ has a positive 0/1 certiﬁed robust error on sample ( x, y ) if and only if exactly one of the following two cases happens:
• g θ ( x ) (cid:54) =
y , i.e. the classiﬁer misclassiﬁes x . • g
θ ( x ) =
y , but CR ( g θ ; x, y ) < (cid:15) , i.e. the classiﬁer is correct but not robust enough.
Thus, the 0/1 certiﬁed robust error can be decomposed as the sum of two error terms: a 0/1 classiﬁcation error and a 0/1 robustness error:
[Equation]
4. D ESIDERATA FOR OBJECTIVE FUNCTIONS
Minimizing the 0-1 error directly is intractable.
A classic method is to minimize a surrogate loss instead.
The surrogate loss for the 0/1 classiﬁcation error is called classiﬁcation loss and denoted by l C ( g θ ; x, y ) .
The surrogate loss for the 0/1 robustness error is called robustness loss and denoted by l R ( g θ ; x, y ) .
Our ﬁnal objective function is
[Equation]
We would like our loss functions l C ( g θ ; x, y ) and l R ( g θ ; x, y ) to satisfy some favorable conditions.
These conditions are summarized below as (C1) - (C3):
• (C1) (Surrogate condition):
Surrogate loss should be an upper bound of the original error function, i.e. l C ( g θ ; x, y ) and l R ( g θ ; x, y ) should be upper bounds of 1 { g θ ( x ) (cid:54) =
y } and 1 { g θ ( x )=
y,CR ( g θ ; x,y ) <(cid:15) } , respectively.
• (C2) (Differentiablity): l C ( g θ ; x, y ) and l R ( g θ ; x, y ) should be (sub-)differentiable with respect to θ .
• (C3) (Numerical stability): The computation of l C ( g θ ; x, y ) and l R ( g θ ; x, y ) and their (sub- )gradients with respect to θ should be numerically stable.
The surrogate condition (C1) ensures that l ( g θ ; x, y ) itself meets the surrogate condition, i.e.
[Equation]
Conditions (C2) and (C3) ensure that (10) can be stably minimized with ﬁrst order methods.
4. S URROGATE LOSSES ( FOR C ONDITION C1)
We next discuss choices of the surrogate losses that ensure we satisfy condition (C1).
The classiﬁcation surrogate loss is relatively easy to design.
There are many widely used loss functions from which we can choose, and in this work we choose the cross-entropy loss as the classiﬁcation loss:
[Equation]
[Equation]
For the robustness surrogate loss, we choose the hinge loss on the certiﬁed radius:
[Equation]
[Equation]
where ˜ (cid:15) > 0 and λ ≥ 1˜ (cid:15) .
We use the hinge loss because not only does it satisfy the surrogate condition, but also it is numerically stable, which we will discuss in Section 4.4.
4. D IFFERENTIABLE CERTIFIED RADIUS VIA SOFT RANDOMIZED SMOOTHING ( FOR C ONDITION C2)
The classiﬁcation surrogate loss in (12) is differentiable with respect to θ , but the differentiability of the robustness surrogate loss in (13) requires differentiability of CR ( g θ ; x, y ) .
In this section we will show that the randomized smoothing certiﬁed radius in (8) does not meet condition (C2), and accordingly, we will introduce soft randomized smoothing to solve this problem.
Whether the certiﬁed radius (8) is sub-differentiable with respect to θ boils down to the differentiablity of E η 1 { f θ ( x + η )= y } .
Theoretically, the expectation is indeed differentiable.
However, from a practical point of view, the expectation needs to be estimated by Monte Carlo sampling
E η 1 { f θ ( x + η )=
y } ≈ 1 k (cid:80) kj =1 1 { f θ ( x + η j )=
y } , where η j is i.i.d Gaussian noise and k is the number of samples.
This estimation, which is a sum of indicator functions, is not differentiable.
Hence, condition (C2) is still not met from the algorithmic perspective.
To tackle this problem, we leverage soft randomized smoothing (Soft-RS).
In contrast to the original version of randomized smoothing (Hard-RS), Soft-RS is applied to a neural network z θ ( x ) whose last layer is softmax.
The soft smoothed classiﬁer ˜ g θ is deﬁned as follows.
Deﬁnition 2.
For a neural network z θ : X → P ( K ) whose last layer is softmax and σ > 0 , the soft smoothed classiﬁer ˜ g θ of z θ is deﬁned as
[Equation]
Using Lemma 2 in Salman et al.
(2019), we prove the following theorem in Appendix A:
Theorem 2.
Let the ground truth of an input x be y .
If ˜ g θ classiﬁes x correctly, i.e.
[Equation]
Then ˜ g θ is provably robust at x, with the certiﬁed radius given by
[Equation]
where Φ is the c.d.f.
of the standard Gaussian distribution.
We notice that in Salman et al.
(2019) (see its Appendix B), a similar technique was introduced to overcome the non-differentiability in creating adversarial examples to a smoothed classiﬁer.
Different from their work, our method uses Soft-RS to obtain a certiﬁed radius that is differentiable in practice.
The certiﬁed radius given by soft randomized smoothing meets condition (C2) in the algorithmic design.
Even if we use Monte Carlo sampling to estimate the expectation, (16) is still sub-differentiable with respect to θ as long as z θ is sub-differentiable with respect to θ .
Connection between Soft-RS and Hard-RS We highlight two main properties of Soft-RS.
Firstly, it is a differentiable approximation of the original Hard-RS.
To see this, note that when β → ∞ , z yθ ( x ; β ) a.e. −−→ 1 { y =argmax c u cθ ( x ) } , so ˜
g θ converges to g θ almost everywhere.
Consequently, the Soft-RS certiﬁed radius (16) converges to the Hard-RS certiﬁed radius (8) almost everywhere as β goes to inﬁnity.
Secondly, Soft-RS itself provides an alternative way to get a provable robustness guarantee.
In Appendix A, we will provide Soft-RS certiﬁcation procedures that certify ˜ g θ with the Hoeffding bound or the empirical Bernstein bound.
4. N UMERICAL S TABILITY ( FOR C ONDITION C3)
In this section, we will address the numerical stability condition (C3).
While Soft-RS does provide us with a differentiable certiﬁed radius (16) which we could maximize with ﬁrst-order optimization methods, directly optimizing (16) suffers from exploding gradients.
The problem stems from the inverse cumulative density function Φ − 1 ( x ) , whose derivative is huge when x is close to 0 or 1.
Fortunately, by minimizing the robustness loss (13) instead, we can maximize the robust radius free from exploding gradients.
The hinge loss restricts that samples with non-zero robustness loss must satisfy 0 < CR (˜ g θ ; x, y ) < (cid:15) + ˜ (cid:15) , which is equivalent to 0 < ξ θ ( x, y ) < γ where ξ θ ( x, y ) =
Φ − 1 ( E η [ z yθ ( x + η )]) − Φ − 1 (max y (cid:48)
(cid:54) =
y E η
[ z y (cid:48) θ ( x + η )]) and γ = 2( (cid:15) +˜ (cid:15) ) σ .
Under this restriction, the derivative of Φ − 1 is always bounded as shown in the following proposition.
The proof can be found in Appendix B.
Proposition 1.
Given any p 1 , p 2 , ...
p K satisﬁes p 1 ≥ p 2 ≥ ... ≥ p K ≥ 0 and p 1 + p
+ ...
+ p K
= 1 , let γ = 2( (cid:15) +˜ (cid:15) )
σ , the derivative of min { [Φ − 1 ( p 1 ) − Φ − 1 ( p 2 )] , γ } with respect to p 1 and p 2 is bounded.
4. C OMPLETE IMPLEMENTATION
We are now ready to present the complete MACER algorithm.
Expectations over Gaussian samples are approximated with Monte Carlo sampling.
Let η 1 , · · · , η k be k i.i.d.
samples from N (0 , σ 2 I ) .
The ﬁnal objective function is
[Equation]
where ˆ z θ ( x ) = 1 k (cid:80) kj =1 z θ ( x + η j ) is the empirical expectation of z θ ( x + η ) and ˆ ξ θ ( x, y ) =
Φ − 1 (ˆ z yθ ( x )) − Φ − 1 (max y (cid:48)
(cid:54) =
y ˆ z y (cid:48) θ ( x )) .
During training we minimize E ( x,y ) ∼ ˆ p data l (˜ g θ ; x, y ) .
Detailed implementation is described in Algorithm 1.
To simplify the implementation, we choose γ to be a hyperparameter instead of ˜ (cid:15) .
The inverse temperature of softmax β is also a hyperparameter.
, · · · , x ik ∼ N ( x, σ 2 I ) 5:
Compute the empirical expectations:
ˆ z θ ( x i ) ← (cid:80) kj =1 z θ ( x ij ) /k
for i = 1 , · · · , n 6:
Compute G θ = { ( x i , y i ) :
˜ g θ ( x i ) =
y i } : ( x i , y i )
∈ G θ ⇔ y i =
arg max c ∈Y ˆ z cθ ( x i ) 7:
For each ( x i , y i ) ∈ G θ , compute ˆ y i :
ˆ y
i ← arg max c ∈Y\{ y i } ˆ z cθ ( x i ) 8:
For each ( x i , y i ) ∈ G θ , compute ˆ ξ θ ( x i , y i ) :
ˆ ξ θ ( x i , y i )
← Φ − 1 (ˆ z y
i θ ( x i ))
− Φ − 1 (ˆ z ˆ y i θ ( x i )) 9:
Update θ with one step of any ﬁrst-order optimization method to minimize
[Equation]
10: end for
Compare to adversarial training Adversarial training deﬁnes the problem as a mini-max game and solves it by optimizing the inner loop (attack generation) and the outer loop (model update) iteratively.
In our method, we only have a single loop (model update).
As a result, our proposed algorithm can run much faster than adversarial training because it does not require additional back propagations to generate adversarial examples.
Compare to previous work The overall objective function of our method, a linear combination of a classiﬁcation loss and a robustness loss, is similar to those of adversarial logit pairing (ALP) (Kannan et al., 2018) and TRADES (Zhang et al., 2019b).
In MACER, the λ in the objective function (17) can also be viewed as a trade-off factor between accuracy and robustness.
However, the robustness term of MACER does not depend on a particular adversarial example x (cid:48) , which makes it substantially different from ALP and TRADES.
E XPERIMENTS
In this section, we empirically evaluate our proposed MACER algorithm on a wide range of tasks.
We also study the inﬂuence of different hyperparameters in MACER on the ﬁnal model performance.
5. S ETUP
To fairly compare with previous works, we follow Cohen et al.
and Salman et al.
(2019) to use LeNet for MNIST, ResNet-110 for Cifar-10 and SVHN, and ResNet-50 for ImageNet.
MACER Training For Cifar-10, MNIST and SVHN, we train the models for 440 epochs using our proposed algorithm.
The learning rate is initialized to be 0.01, and is decayed by 0.1 at the 200 th /400 th epoch.
For all the models, we use k = 16 , γ = 8 . 0 and β = 16 . 0 .
The value of λ trades off the accuracy and robustness and we ﬁnd that different λ leads to different robust accuracy when the model is injected by different levels ( σ ) of noise.
We ﬁnd setting λ = 12 .
for σ = 0 .
25 and λ = 4 .
for σ = 0 .
50 works best.
For ImageNet, we train the models for 120 epochs.
The initial learning rate is set to be 0.1 and is decayed by 0.1 at the 30 th /60 th /90 th epoch.
For all models on
ImageNet, we use k = 2 , γ = 8 . 0 and β = 16 . 0 .
More details can be found in Appendix C.
Baselines We compare the performance of MACER with two previous works.
The ﬁrst work (Cohen et al., 2019) trains smoothed networks by simply minimizing cross-entropy loss.
The second one (Salman et al., 2019) uses adversarial training on smoothed networks to improve the robustness.
For both baselines, we use checkpoints provided by the authors and report their original numbers whenever available.
In addition, we run Cohen et al.
(2019)’s method on all tasks as it is a speical case of MACER by setting k = 1 and λ = 0 .
Certiﬁcation Following previous works, we report the approximated certiﬁed test set accuracy , which is the fraction of the test set that can be certiﬁed to be robust at radius r .
However, the approximated certiﬁed test set accuracy is a function of the radius r .
It is hard to compare two models unless one is uniformly better than the other for all r .
Hence, we also use the average certiﬁed radius (ACR) as a metric: for each test data ( x, y ) and model g , we can estimate the certiﬁed radius CR ( g ; x, y ) .
The average certiﬁed radius is deﬁned as 1 |S test | (cid:80) ( x,y ) ∈S test CR ( g ; x, y ) where
S test is the test set.
To estimate the certiﬁed radius for data points, we use the source code provided by Cohen et al.
5. R ESULTS
We report the results on Cifar-10 and ImageNet in the main body of the paper.
Results on MNIST and SVHN can be found in Appendix C.2.
[Table]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Figure] [Figure]
[Table]
[Figure]
Performance
The performance of different models on Cifar-10 are reported in Table 1, and in
Figure 1 we display the radius-accuracy curves.
Note that the area under a radius-accuracy curve is equal to the ACR of the model.
First, the plots show that our proposed method consistently achieves signiﬁcantly higher approximated certiﬁed test set accuracy than Cohen et al.
This shows that robust training via maximizing the certiﬁed radius is more effective than simply minimizing the cross entropy classiﬁcation loss.
Second, the performance of our model is different from that of
Salman et al.
for different r .
For example, for σ = 0 . 25 , our model achieves higher accuracy than Salman et al.
(2019)’s model when r = 0 / 0 .
5 , but the performance of ours is worse when r = 0 .
For the average certiﬁed radius, our models are better than Salman et al.
’s modelsin all settings.
For example, when σ = 0 .
50 , the ACR of our model is about 3% larger than that of Salman et al.
(2019)’s.
The gain of our model is relatively smaller when σ = 1 . 0 .
This is because σ = 1 .
is a very large noise level (Cohen et al., 2019) and both models perform poorly.
The ImageNet results are displayed in Table 2 and Figure 2, and the observation is similar.
All experimental results show that our proposed algorithm is more effective than previous ones.
Training speed Since MACER does not require adversarial attack during training, it runs much faster to learn a robust model.
Empirically, we compare MACER with Salman et al.
(2019) on the average training time per epoch and the total training hours, and list the statistics in Table 3.
For a fair comparison, we use the codes 34 provided by the original authors and run all algorithms on the same machine.
For Cifar-10 we use one NVIDIA P100 GPU and for ImageNet we use four NVIDIA
P100 GPUs.
According to our experiments, on ImageNet, MACER achieves ACR=0.544 in 117.
hours.
On the contrary, Salman et al.
(2019) only achieves ACR=0.528 but uses 193.10 hours, which clearly shows that our method is much more efﬁcient.
One might question whether the higher performance of MACER comes from the fact that we train for more epochs than previous methods.
In Section C.3 we also run MACER for 150 epochs and compare it with the models in Table 3.
The results show that when run for only 150 epochs, MACER still achieves a performance comparable with SmoothAdv, and is 4 times faster at the same time.
Dataset
Model
[Table]
Cifar
[Figure]
[Table]
ImageNet
[Table]
[Figure]
[Table]
[Figure]
5. E FFECT OF HYPERPARAMETERS
In this section, we carefully examine the effect of different hyperparameters in MACER.
All experiments are run on Cifar-10 with σ = 0 .
25 or 0 .
The results for σ = 0 .
25 are shown in Figure 3.
All details can be found in Appendix C.4.
Effect of k
We sample k Gaussian samples for each input to estimate the expectation in (16).
We can see from Figure 3(a) that using more Gaussian samples usually leads to better performance.
For example, the radius-accuracy curve of k = 16 is uniformly above that of k = 1 .
Effect of λ
The radius-accuracy curves in Figure 3(b) demonstrate the trade-off effect of λ .
From the ﬁgure, we can see that as λ increases, the clean accuracy drops while the certiﬁed accuracy at large radii increases.
Effect of γ γ is deﬁned as the hyperparameter in the hinge loss.
From Figure 3(c) we can see that when γ is small, the approximated certiﬁed test set accuracy at large radii is small since γ “truncates” the large radii.
As γ increases, the robust accuracy improves.
It appears that γ also acts as a trade-off between accuracy and robustness, but the effect is not as signiﬁcant as the effect of λ .
Effect of β Similar to Salman et al.
(2019)’s ﬁnding (see its Appendix B), we also observe that using a larger β produces better results.
While Salman et al.
(2019) pointed out that a large β may make training unstable, we ﬁnd that if we only apply a large β to the robustness loss, we can maintain training stability and achieve a larger average certiﬁed radius as well.
C ONCLUSION AND FUTURE WORK
In this work we propose MACER, an attack-free and scalable robust training method via directly maximizing the certiﬁed radius of a smoothed classiﬁer.
We discuss the desiderata such an algorithm would have to satisfy, and provide an approach to each of them.
According to our extensive experiments, MACER performs better than previous provable l 2 -defenses and trains faster.
Our strong empirical results suggest that adversarial training is not a must for robust training, and defense based on certiﬁcation is a promising direction for future research.
Moreover, several recent papers (Carmon et al., 2019; Zhai et al., 2019; Stanforth et al., 2019) suggest that using unlabeled data helps improve adversarially robust generalization.
We will also extend MACER to the semisupervised setting.
A CKNOWLEDGMENTS
We thank Tianle Cai for helpful discussions and suggestions.
This work was done when Runtian
Zhai was visiting UCLA under the Top-Notch Undergraduate Program of Peking University school of EECS.
Chen Dan and Pradeep Ravikumar acknowledge the support of Rakuten Inc., and NSF via IIS1909816.
Huan Zhang and Cho-Jui Hsieh acknowledge the support of NSF via IIS1719097.
Liwei Wang acknowledges the support of Beijing Academy of Artiﬁcial Intelligence
A S OFT RANDOMIZED SMOOTHING
In this section we provide theoretical analysis and certiﬁcation procedures for Soft-RS.
A. P ROOF OF THEOREM
Our proof is based on the following lemma:
Lemma 1.
For any measurable function f : X → [0 , 1] , deﬁne ˆ f ( x ) =
E η ∼N (0 ,σ 2 I ) f
( x + η ) , then x (cid:55)→ Φ − 1 ( ˆ f ( x )) is 1 /σ -Lipschitz.
This lemma is the generalized version of Lemma 2 in Salman et al.
Proof of Theorem 2.
Let y ∗ =
arg max y (cid:48)
(cid:54) =
y E η
[ z y (cid:48) θ ( x + η )] .
For any c ∈ Y , deﬁne ˆ z cθ as:
[Equation]
Because z cθ : X → [0 , 1] , by Lemma 1 we have x (cid:55)→ Φ − 1 (ˆ z cθ ( x )) is 1 /σ -Lipschitz.
Thus, ∀ y (cid:48) (cid:54) =
y , for any δ
such that (cid:107) δ (cid:107) 2 ≤ σ 2 [Φ − 1 ( E η [ z yθ ( x + η )]) − Φ − 1 (max y (cid:48) (cid:54) =
y E η
[ z y (cid:48) θ ( x + η )])] :
[Equation]
Therefore, Φ − 1 ( E η z yθ ( x + δ + η )) ≥ Φ − 1 ( E η z y (cid:48)
θ ( x + δ + η )) .
Due to the monotonicity of Φ − 1 , we have E η z yθ ( x + δ + η ) ≥ E η z y (cid:48)
θ ( x + δ + η ) , which implies that ˜ g θ ( x + δ ) =
y .
A. S OFT -RS CERTIFICATION PROCEDURE
Let z A = E η
[ z yθ ( x + η )] and z B = max y (cid:48) (cid:54) =
y E η
[ z y (cid:48) θ ( x + η )] .
If there exist z A , z B ∈ [0 , 1] such that P ( z
A ≥ z
A ∧ z B ≤ z B ) ≥ 1 − α , then with probability at least 1 − α , CR (˜ g θ ; x, y ) ≥ σ 2 [Φ − 1 ( z A ) − Φ − 1 ( z B )] .
Meanwhile, z B ≤ 1 − z A , so we can take z B = 1 − z A , and
[Equation]
It reduces to ﬁnd a conﬁdence lower bound of z A .
Here we provide two bounds:
Hoeffding Bound
The random variable z yθ ( x + η ) has mean z A , and z y 1 , · · · , z y k are its k observations.
Because z yj ∈ [0 , 1] for any j = 1 , · · · , k , we can use Hoeffding’s inequality to obtain a lower conﬁdence bound:
Lemma 2.
(Hoeffding’s Inequality) Let X 1 , ...,
X k be independent random variables bounded by the interval [0 , 1] .
Let X = 1 k (cid:80) kj =1 X j , then for any t ≥
[Equation]
Denote ˆ z y = 1 k (cid:80) kj =1 z yj .
By Hoeffding’s inequality we have
[Equation]
Hence, a 1 − α conﬁdence lower bound z A of z
A is
[Equation]
Empirical Bernstein Bound Maurer & Pontil (2009) provides us with a tighter bound:
Theorem 3.
(Theorem 4 in Maurer & Pontil (2009))
Under the conditions of Lemma 2, with probability at least 1 − α ,
[Equation]
where S 2 is the sample variance of X 1 , · · · , X k , i.e.
[Equation]
=
[Equation] [Equation]
Consequently, a 1 − α conﬁdence lower bound z A of z
A is
[Equation]
The full certiﬁcation procedure with the above two bounds is described in Algorithm 2.
n c A ← arg max c ˆ z 0 c 5: z
A ← S
U NDER N OISE ( z, x, n,
[Equation]
)[1 , ˆ c
A ] /n 6:
z A ← ˆ z A − (cid:113) − log α 2 n 7: if z A > 12 then return prediction ˆ c A and radius σ Φ − 1 ( z A ) 8: else return ABSTAIN 9: end function 10: # Certify with empirical Bernstein bound 11: function
2 )[1 , :] /n
: ˆ c A ← arg max c ˆ z 0 c 14:
A ← S AMPLE U NDER N OISE ( z, x, n, σ 2 ) 15: ˆ z A ← A [1 , ˆ c A ] /n , S
A ← A [2 , ˆ c A ] − A [1 , ˆ c A ] 2 /n n −16:
z A ← ˆ z A − (cid:113) 2 S 2 A log(2 /α ) n − 7log(2 /α ) 3( n − 1) 17: if z A > 12 then return prediction ˆ c A and radius σ Φ − 1 ( z A ) 18: else return ABSTAIN 19: end function 20: # Helper function: draw num samples from z ( x + η ) and return the 1 st and 2 nd sample moment 21: function S AMPLE U NDER N OISE ( z , x , num, σ 2 ) 22:
Initialize a 2 × K matrix A ← (0 , · · · , 0; 0 , · · · , 0) 23: for j = 1 to num do 24:
Sample noise η j ∼ N (0 , σ 2 I ) 25:
Compute: z j = z ( x + η j ) 26:
Increment: A [1 , :] ←
A [1 , :]
+ z j , A [2 , :] ←
A [2 , :] + z 2 j 27: end for 28: return A 29: end function
A. C OMPARING S OFT -RS WITH H ARD -RS
We use Soft-RS during training and use Hard-RS during certiﬁcation.
In this section, we empirically compare these two certiﬁcation methods.
We certify the nine models in Table 4.
For each model, we certify with both Hard-RS and Soft-RS.
For Hard-RS, we use Clopper-Pearson bound and for
Soft-RS, we use the empirical Bernstein bound with different choices of β .
The results are displayed in Figure 4.
The results show that Hard-RS consistently gives a larger lower bound of robust radius than Soft-RS.
We also observe that there is a gap between Soft-RS and Hard-RS when β → ∞ , which implies that the empirical Bernstein bound, though tighter than the Hoeffding bound, is still looser than the Clopper-Pearson bound.
B P ROOF OF P ROPOSITION
Proof of Proposition 1.
We only need to consider the case when Φ − 1 ( p 1 ) − Φ − 1 ( p 2 )
≤ γ since the derivative is zero when Φ − 1 ( p 1 ) − Φ − 1 ( p 2 ) > γ .
Obviously, p 2 ≤ 0 .
5 and thus Φ − 1 ( p 2 ) ≤ 0 .
So Φ − 1 ( p 1 ) ≤ γ .
Deﬁne p ∗ ∈ (0 , 1) such that Φ − 1 ( p ∗ ) = γ .
Since Φ − 1 ( p ) is a strictly increasing function of p , p ∗ is unique, and p 1 ≤ p ∗ .
min { [Φ − 1 ( p 1 ) − Φ − 1 ( p 2 )] , γ } =
Φ − 1 ( p 1 ) − Φ − 1 ( p 2 ) .
Since p 1 is the largest value and p 1 + p 2 + ...
+ p K
= 1 , we have 1 K ≤ p 1 ≤ p ∗ .
Since [Φ − 1 ] (cid:48) ( p ) is continuous in any closed interval of (0 , 1) , the derivative of Φ − 1 ( p 1 ) − Φ − 1 ( p 2 ) with respect to p 1 is bounded.
Similarly, p 2 is the largest among p 2 , ...
p K and ( K − 1) p 2 ≥ p 2 + ...
+ p K = 1 − p 1 ≥ 1 − p ∗ .
Thus 1 − p ∗ ≥ p 2 ≥ 1 − p ∗ K − 1 , and the derivative of Φ − 1 ( p 1 ) − Φ − 1 ( p 2 ) with respect to p 2 is bounded.
C S UPPLEMENTARY MATERIAL FOR EXPERIMENTS C. C OMPARED MODELS
In this section we list all compared models in the main body of this paper.
Cifar-10 models are listed in Table 4, and ImageNet models are listed in Table 5.
[Table]
[Table]
C. R ESULTS ON MNIST AND SVHN
Here we present experimental results on MNIST and SVHN.
For comparison we also report the results produced by Cohen et al.
(2019)’s method.
[Table]
[Table] [Table]
[Figure]
[Table]
[Figure]
[Table]
[Figure]
[Table]
The results are reported in Table 6.
For all σ , we use k = 16 , λ = 16 . 0 , γ = 8 . 0 and β = 16 . 0 .
[Table]
C.2. SVHN
The results are reported in Table 7.
We use k = 16 , λ = 12 . 0 , γ = 8 . 0 and β = 16 . 0 .
[Table]
C. MACER T RAINING FOR 150 EPOCHS
In Table 8 we report the performance and training time of MACER on Cifar-10 when it is only run for 150 epochs, and compare with SmoothAdv (Salman et al., 2019) and MACER (440 epochs)
[Table]
The learning rate is decayed by 0.1 at epochs 60 and 120.
All other hyperparameters are kept the same as in Table 4.
[Table]
C. E FFECT OF HYPERPARAMETERS
All experiments are run on Cifar-10 with σ = 0 .
25 or 0 .
See Table 9 for detailed experimental settings.
Results are reported in Tables 10-13.
[Table] [Table]
[Table]
[Table] [Table]
[Table] [Table]
[Table] [Table] [Table]
[Table] [Table] [Table] [Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table] [Table] [Table]
[Table]
[Table]
[Table]
[Table]
[Table]
[Table]