R ETHINKING S OFTMAX C ROSS -E NTROPY L OSS FOR A DVERSARIAL R OBUSTNESS
Anonymous authors
Paper under double-blind review
A BSTRACT
Previous work shows that adversarially robust generalization requires larger sample complexity, and the same dataset, e.g., CIFAR-10, which enables good standard accuracy may not sufﬁce to train robust models.
Since collecting new training data could be costly, we focus on better utilizing the given data by inducing the regions with high sample density in the feature space, which could lead to locally sufﬁcient samples for robust learning.
We ﬁrst formally show that the softmax cross-entropy (SCE) loss and its variants convey inappropriate supervisory signals, which encourage the learned feature points to spread over the space sparsely in training.
This inspires us to propose the Max-Mahalanobis center (MMC) loss to explicitly induce dense feature regions in order to beneﬁt robustness.
Namely, the
MMC loss encourages the model to concentrate on learning ordered and compact representations, which gather around the preset optimal centers for different classes.
We empirically demonstrate that applying the MMC loss can signiﬁcantly improve robustness even under strong adaptive attacks, while keeping high accuracy on clean inputs comparable to the SCE loss with little extra computation.
I NTRODUCTION
The deep neural networks (DNNs) trained by the softmax cross-entropy (SCE) loss have achieved state-of-the-art performance on various tasks (Goodfellow et al., 2016).
However, in terms of robustness, the SCE loss is not sufﬁcient to lead to satisfactory performance of the trained models.
It has been widely recognized that the DNNs trained by the SCE loss are vulnerable to adversarial attacks (Carlini & Wagner, 2017a; Goodfellow et al., 2015; Kurakin et al., 2017; Moosavi-Dezfooli et al., 2016; Papernot et al., 2016), where human imperceptible perturbations can be crafted to fool a high-performance network.
To improve adversarial robustness of classiﬁers, various kinds of defenses have been proposed, but many of them are quickly shown to be ineffective to the adaptive attacks , which are adapted to the speciﬁc details of the proposed defenses (Athalye et al., 2018).
Besides, the methods on veriﬁcation and training provably robust networks have been proposed (Dvijotham et al., 2018a;b; Hein & Andriushchenko, 2017; Wong & Kolter, 2018).
While these methods are exciting, the veriﬁcation process is often slow and not scalable.
Among the previously proposed defenses, the adversarial training (AT) methods can achieve state-of-the-art robustness under different adversarial settings (Madry et al., 2018; Zhang et al., 2019b).
These methods either directly impose the AT mechanism on the SCE loss or add additional regularizers.
Although the AT methods are relatively strong, they could sacriﬁce accuracy on clean inputs and are computationally expensive (Xie et al., 2019).
Due to the computational obstruction, many recent efforts have been devoted to proposing faster veriﬁcation methods (Wong et al., 2018;
Xiao et al., 2019) and accelerating AT procedures (Shafahi et al., 2019; Zhang et al., 2019a).
However, the problem still remains.
Schmidt et al.
(2018) show that the sample complexity of robust learning can be signiﬁcantly larger than that of standard learning.
Given the difﬁculty of training robust classiﬁers in practice, they further postulate that the difﬁculty could stem from the insufﬁciency of training samples in the commonly used datasets, e.g., CIFAR-10 (Krizhevsky & Hinton, 2009).
Recent work intends to solve this problem by utilizing extra unlabeled data (Carmon et al., 2019;
Stanforth et al., 2019), while we focus on the complementary strategy to exploit the labeled data in hand more efﬁciently.
Note that although the samples in the input space are unchangeable, we could instead manipulate the local sample distribution, i.e., sample density in the feature space via appropriate training objectives.
Intuitively, by inducing high-density feature regions, there would be locally sufﬁcient samples to train robust classiﬁers and return reliable predictions (Schmidt et al., 2018).
[Figure]
Similar to our attempt to induce high-density regions in the feature space, previous work has been proposed to improve intra-class compactness.
Contrastive loss (Sun et al., 2014) and triplet loss (Schroff et al., 2015) are two classical objectives for this purpose, but the training iterations will dramatically grow to construct image pairs or triplets, which results in slow convergence and instability.
The center loss (Wen et al., 2016) avoids the pair-wise or triplet-wise computation by minimizing the squared distance between the features and the corresponding class centers.
However, since the class centers are updated w.r.t.
the learned features during training, the center loss has to be jointly used with the SCE loss to seek for a trade-off between inter-class dispersion and intra-class compactness.
Therefore, the center loss cannot concentrate on inducing strong intra-class compactness to construct high-density regions and consequently could not lead to reliable robustness, as shown in our experiments.
In this paper, we ﬁrst formally analyze the sample density distribution induced by the SCE loss and its other variants (Pang et al., 2018; Wan et al., 2018) in Sec. 3.2, which demonstrates that these previously proposed objectives convey unexpected supervisory signals on the training points, which make the learned features tend to spread over the space sparsely.
This undesirable behavior mainly roots from applying the softmax function in training , which makes the loss function only depend on the relative relation among logits and cannot directly supervise on the learned representations.
We further propose a novel training objective which can explicitly induce high-density regions in the feature space and learn more structured representations.
To achieve this, we propose the MaxMahalanobis center (MMC) loss (detailed in Eq.
(8)) as the substitute of the SCE loss.
Speciﬁcally, in the MMC loss, we ﬁrst preset untrainable class centers with optimal inter-class dispersion in the feature space according to Pang et al.
(2018), then we encourage the features to gather around the centers by minimizing the squared distance similar with the center loss.
The MMC loss can explicitly control the inter-class dispersion by a single hyperparameter, and further concentrate on improving intra-class compactness in the training procedure to induce high-density regions, as intuitively shown in Fig. 1.
Behind the simple formula, the MMC loss elegantly combines the favorable merits of the previous methods, which leads to a considerable improvement on the adversarial robustness.
In experiments, we follow the suggestion by Carlini et al.
(2019) that we test under different threat models and attacks, including the adaptive attacks (Athalye et al., 2018) on MNIST, CIFAR-10, and CIFAR-100 (Krizhevsky & Hinton, 2009; LeCun et al., 1998).
The results demonstrate that our method can lead to reliable robustness of the trained models with little extra computation, while maintaining high clean accuracy with faster convergence rates compared to the SCE loss and its variants.
When combined with the existing defense mechanisms, e.g., the AT methods (Madry et al., 2018), the trained models can be further enhanced under the attacks different from the one used to craft adversarial examples for training.
P RELIMINARIES
This section ﬁrst provides the notations, then introduces the adversarial attacks and threat models.
2. N OTATIONS
In this paper, we use the lowercases to denote variables and the uppercases to denote mappings.
Let L be the number of classes, we deﬁne the softmax function softmax( h ) :
R L → R L as softmax( h ) i = exp( h i ) / (cid:80) Ll =1 exp( h l ) , i ∈
[ L ] , where [ L ] := { 1 , · · · , L } and h is termed as logit.
A deep neural network (DNN) learns a non-linear mapping from the input x ∈ R p to the feature z
= Z ( x ) ∈ R d .
One common training objective for DNNs is the softmax cross-entropy (SCE) loss:
[Equation]
for a single input-label pair ( x, y ) , where 1 y is the one-hot encoding of y and the logarithm is deﬁned as element-wise.
Here W and b are the weight matrix and bias vector of the SCE loss, respectively.
2. A DVERSARIAL ATTACKS AND THREAT MODELS
Previous work has shown that adversarial examples can be easily crafted to fool DNNs (Biggio et al., 2013; Nguyen et al., 2015; Szegedy et al., 2014).
A large amount of attacking methods on generating adversarial examples have been introduced in recent years (Carlini & Wagner, 2017a;
Chen et al., 2017; Dong et al., 2018; Goodfellow et al., 2015; Ilyas et al., 2018; Kurakin et al., 2017; Madry et al., 2018; Moosavi-Dezfooli et al., 2016; Papernot et al., 2016; Uesato et al., 2018).
Given the space limit, we try to perform a comprehensive evaluation by considering ﬁve different threat models and choosing representative attacks for each threat model following Carlini et al.
White-box l ∞ distortion attack: We apply the projected gradient descent ( PGD ) (Madry et al., 2018) method, which is efﬁcient and widely studied
in previous
work (
Pang et al., 2019)
White-box l 2 distortion attack
: We apply the C&W (Carlini & Wagner, 2017a) method, which has a binary search mechanism on its parameters to ﬁnd the minimal l 2 distortion for a successful attack.
Black-box transfer-based attack: We use the momentum iterative method ( MIM ) (Dong et al., 2018) that is effective on boosting adversarial transferability (Kurakin et al., 2018).
Black-box gradient-free attack
: We choose SPSA (Uesato et al., 2018) since it has broken many previously proposed defenses.
It can still perform well even when the loss is difﬁcult to optimize.
General-purpose attack: We also evaluate the general robustness of
models
when adding Gaussian
noise (Gilmer et al., 2019) or random rotation (Engstrom et al., 2019) on the input images.
Furthermore, to exclude the false robustness caused by, e.g., gradient mask (Athalye et al., 2018), we modify the above attacking methods to be adaptive attacks (Carlini & Wagner, 2017b; Carlini et al., 2019; Herley & Van Oorschot, 2017) when evaluating on the robustness of our method.
The adaptive attacks are much more powerful than the non-adaptive ones, as detailed in Sec. 4.2.
M ETHODOLOGY
Various theoretical explanations have been developed for adversarial examples (Fawzi et al., 2016; 2018; Ilyas et al., 2019; Papernot et al., 2018).
In particular, Schmidt et al.
(2018) show that training robust classiﬁers requires signiﬁcantly larger sample complexity compared to that of training standard ones, and they further postulate that the difﬁculty of training robust classiﬁers stems from, at least partly, the insufﬁciency of training samples in the common datasets.
Recent efforts propose alternatives to beneﬁt training with extra unlabeled data (Carmon et al., 2019; Stanforth et al., 2019), while we explore the complementary way to better use the labeled training samples for robust learning.
Although a given sample is ﬁxed in the input space, we can instead manipulate the local sample distribution, i.e., sample density in the feature space, via designing appropriate training objectives.
Intuitively, by inducing high-density regions in the feature space, it can be expected to have locally sufﬁcient samples to train robust models that are able to return reliable predictions.
In this section, we ﬁrst formally deﬁne the notion of sample density in the feature space.
Then we provide theoretical analyses of the sample density induced by the SCE loss and its variants.
Finally, we propose our new
Max-Mahalanobis center (MMC) loss and demonstrate its superiority compared to previous losses.
3. S AMPLE DENSITY IN THE FEATURE SPACE
Given a training dataset D with N input-label pairs, and the feature mapping Z trained by the objective L ( Z ( x ) , y ) on this dataset, we deﬁne the sample density nearby the feature point z
= Z ( x ) following the similar deﬁnition in physics (Jackson, 1999) as
[Equation]
Here Vol ( · ) denotes the volume of the input set, ∆ B is a small neighbourhood containing the feature point z , and ∆ N = | Z ( D ) ∩ ∆ B | is the number of training points in ∆ B , where Z ( D ) is the set of all mapped features for the inputs in D .
Note that the mapped feature z is still of the label y .
In the training procedure, the feature distribution is directly induced by the training loss L , where minimizing the loss value is the only supervisory signal for the feature points to move (Goodfellow et al., 2016).
This means that the sample density varies mainly along the orthogonal direction w.r.t.
the loss contours, while the density along a certain contour could be approximately considered as the same.
For example, in the right panel of Fig. 1, the sample density induced by our MMC loss (detailed in Sec. 3.3) changes mainly along the radial direction, i.e., the directions of red arrows, where the loss contours are dashed concentric circles.
Therefore, supposing L ( z, y ) =
C , we choose ∆ B = { z ∈ R d |L ( z , y ) ∈
[ C, C + ∆ C ] } , where ∆ C > 0 is a small value.
Then Vol (∆ B ) is the volume between the loss contours of C and C + ∆ C for label y in the feature space.
3. T HE SAMPLE DENSITY INDUCED BY THE GENERALIZED SCE LOSS
Generalized SCE loss.
To better understand how the SCE loss and its variants (Pang et al., 2018;
Wan et al., 2018) affect the sample density of features, we ﬁrst generalize the deﬁnition in Eq.
(1) as:
[Equation]
where the logit h
= H ( z ) ∈ R L is a general transformation of the feature z , for example, h =
Wz + b in the SCE loss.
We call this family of losses as the generalized SCE (g-SCE) loss.
Wan et al.
(2018) propose the large-margin Gaussian Mixture (L-GM) loss, where h i = − ( z − µ i ) (cid:62)
Σ i ( z − µ i ) − mδ i,y under the assumption that the learned features z distribute as a mixture of Gaussian.
Here µ i and Σ
i are extra trainable means and covariance matrices respectively, m is the margin, and δ i,y is the indicator function.
Pang et al.
(2018) propose the Max-Mahalanobis linear discriminant analysis (MMLDA) loss, where h i = −(cid:107)
z − µ ∗ i (cid:107) 22 under the similar mixture of Gaussian assumption, but the main difference is that µ ∗ i are not trainable, but calculated before training with optimal inter-class dispersion.
These two losses both fall into the family of the g-SCE loss with quadratic logits:
[Equation]
where B i are the bias variables.
Besides, note that for the SCE loss, there is
[Equation]
According to Eq.
(4), the SCE loss can also be regraded as a special case of the g-SCE loss with quadratic logits, where µ i = 12 W i , B i =
b i + 14 (cid:107) W i
(cid:107) 22 and Σ
i
=
I are identity matrices.
Therefore, later when we refer to the g-SCE loss, we assume that the logits are quadratic as in Eq.
(4) by default.
The contours of the g-SCE loss.
To provide a formal representation of the sample density induced by the g-SCE loss, we ﬁrst derive the formula of the contours, i.e., the closed-form solution of
L g-SCE ( Z ( x ) , y )
=
C in the space of z , where C ∈ (0 , + ∞ ) is a given constant.
Let C e = exp( C ) ∈
(1 , + ∞ ) , from Eq.
(3), we can represent the contours as the solution of log
[Equation]
The function in Eq.
(5) does not provide an intuitive closed-form solution for the contours, since the existence of the term log (cid:104)(cid:80) l (cid:54) =
y exp( h l ) (cid:105) .
However, note that this term belongs to the family of
Log-Sum-Exp (LSE) function, which is a smooth approximation to the maximum function (Nesterov, 2005; Nielsen & Sun, 2016).
Therefore, we can locally approximate the function in Eq.
(5) with
[Equation]
where ˜ y = arg max l (cid:54) =
y h l .
In the following text, we apply colored characters with tilde like ˜ y to better visually distinguish them.
According to Eq.
(6), we can deﬁne L y, ˜ y
( z ) =
log[exp( h ˜ y − h y )
+ 1] as the local approximation of the g-SCE loss nearby the feature point z , and substitute the neighborhood ∆ B by ∆ B y, ˜ y
= { z ∈ R d |L y, ˜ y
( z ) ∈
[ C, C + ∆ C ] } .
For simplicity, we assume scaled identity covariance matrix in Eq.
(4), i.e., Σ i =
σ i
I , where σ i > 0 are scalars.
Through simple derivations (detailed in Appendix A.1), we show that if σ y (cid:54) =
σ ˜ y , the solution of L y,
˜ y
( z ) =
C is a ( d − 1) - dimensional hypersphere with the center M y, ˜ y
= ( σ y − σ ˜ y ) − 1 ( σ y µ y − σ ˜ y µ ˜ y )
; otherwise if σ y = σ ˜ y , the hypersphere-shape contour will degenerate to a hyperplane.
[Figure] [Figure]
The case: # $ < # &$ (Preferred by models since lower loss values) ' ( ∞ , loss value →' ) , -,/- , loss
[Figure]
= 0 ∗ , -,/-
[Figure]
0 ∗
[Figure]
-∗ ,
[Figure]
The induced sample density.
Since the approximation in Eq.
(6) depends on the speciﬁc y and ˜
y , we deﬁne the training subset D k, ˜ k
= { ( x, y ) ∈
D| y
=
k, ˜ y =
˜ k } and N k, ˜ k
= |D k, ˜ k
| .
Intuitively,
D k, ˜ k includes the data with the true label of class k , while the highest prediction returned by the classiﬁer is class ˜ k among other classes.
Then we can derive the approximated sample density in the feature space induced by the g-SCE loss, as stated in the following theorem:
Theorem 1.
(Proof in Appendix A.1)
Given ( x, y ) ∈ D k, ˜ k , z
= Z ( x ) and L g-SCE ( z, y ) =
C , if there are Σ k
= σ k
I , Σ ˜ k
= σ ˜ k
I , and σ k (cid:54) =
σ ˜ k , then the sample density nearby the feature point z based on the approximation in Eq.
(6) is
[Equation]
k
[Equation]
12 , and B k,
[Equation]
where for the input-label pair in D k, ˜ k , there is L g-SCE ∼ p k, ˜ k
( c ) .
Limitations of the g-SCE loss.
Based on Theorem 1 and the approximation in Eq.
(6), let C ∗ =
log(1 + exp( B k,
˜ k
( σ ˜ k − σ k ))) and C ∗ e = exp
( C ∗ ) , such that B k, ˜ k
+ log( C ∗ e − 1) σ k − σ ˜ k = 0 .
According to Appendix A.1, if σ k > σ ˜ k , then C ∗ will act as a tight lower bound for C , i.e., the solution set of C < C ∗ is empty.
This will make the training procedure tend to avoid this case since the loss
C cannot be further minimized to zero, which will introduce unnecessary biases on the returned predictions.
On the other hand, if σ k < σ ˜ k , C could be minimized to zero.
However, when C → 0 , the sample density will also tend to zero since there is B k, ˜ k
+ log( C e − 1) σ k − σ ˜ k
→ ∞ , which means the feature point will be encouraged to go further and further from the hypersphere center M k, ˜ k only to make the loss value C be lower, as intuitively illustrated in Fig. 2(a).
This counter-intuitive behavior mainly roots from applying the softmax function in training.
Namely, the softmax normalization makes the loss value only depend on the relative relation among logits.
This causes indirect and unexpected supervisory signals on the learned features, such that the points with low loss values tend to spread over the space sparsely.
Fortunately, in practice, the feature point will not really move to inﬁnity, since the existence of batch normalization layers (Ioffe & Szegedy, 2015), and the squared radius from the center M k, ˜ k increases as O ( | log C | ) when minimizing the loss C .
These theoretical conclusions are consistent with the empirical observations on the two-dimensional features in previous work ( cf.
Fig.
1 in Wan et al.
Another limitation of the g-SCE loss is that the sample density is proportional to N k, ˜ k , which is on average N/L 2 .
For example, there are around 1 .
3 million training data in ImageNet (Deng et al., 2009), but with a large number of classes L = 1 , 000 , there are averagely less than two samples in each D k, ˜ k .
These limitations inspire us to design the new training loss as in Sec 3.3.
Remark 1.
If σ k = σ ˜ k
(e.g., as in the SCE loss), the features with loss values in [ C, C + ∆ C ] will be encouraged to locate between two hyperplane contours without further supervision, and consequently there will not be explicit supervision on the sample density as shown in the left panel of Fig.
Remark 2.
Except for the g-SCE loss, Wen et al.
(2016) propose the center loss in order to improve the intra-class compactness of learned features, formulated as L Center ( Z ( x ) , y )
= 12 (cid:107)
z − µ y (cid:107) 22 .
Here the center µ y is updated based on a mini-batch of learned features with label y in each training iteration.
The center loss has to be jointly used with the SCE loss as L SCE + λ L Center , since simply supervise the DNNs with the center loss term will cause the learned features and centers to degrade to zeros (Wen et al., 2016).
This makes it difﬁcult to derive a closed-form formula for the induced sample density.
Besides, the center loss method cannot concentrate on improving intra-class compactness, since it has to seek for a trade-off between inter-class dispersion and intra-class compactness.
3. M AX -M AHALANOBIS CENTER LOSS
Inspired by the above analyses, we propose the Max-Mahalanobis center (MMC) loss to explicitly learn more structured representations and induce high-density regions in the feature space.
The MMC loss is deﬁned in a regression form without the softmax function as
[Equation]
Here µ ∗ = { µ ∗ l } l ∈ [ L ] are the centers of the Max-Mahalanobis distribution (MMD)
(Pang et al., 2018).
The MMD is a mixture of Gaussian distribution with identity covariance matrix and preset centers µ ∗ , where (cid:107) µ ∗ l (cid:107)
= C MM for any l ∈ [ L ] , and C MM is a hyperparameter.
These MMD centers are invariable during training, which are crafted according to the criterion: µ ∗ =
[Equation]
Intuitively, this criterion is to maximize the minimal angle between any two centers, which can provide optimal inter-class dispersion as shown in Pang et al.
In Appendix B.1, we provide the generation algorithm for µ ∗ in MMC.
We derive the sample density induced by the MMC loss in the feature space, as stated in Theorem 2.
Similar to the previously introduced notations, here we deﬁne the subset D k
= { ( x, y ) ∈
D| y
= k } and N k = |D
k | .
Theorem 2.
(Proof in Appendix A.2)
Given ( x, y ) ∈
D k , z
= Z ( x ) and L MMC ( z, y )
=
C , the sample density nearby the feature point z is
[Equation]
where for the input-label pair in D k , there is L MMC ∼ p k ( c ) .
According to Theorem 2, there are several attractive merits of the MMC loss, as described below.
Inducing higher sample density.
Compared to Theorem 1, the sample density induced by MMC is proportional to N k rather than N k, ˜ k , where N k is on average N/L .
It facilitates producing higher sample density.
Furthermore, when the loss value C is minimized to zero, the sample density will exponentially increase according to Eq.
(9), as illustrated in Fig. 2(b).
The right panel of Fig.
1 also provides an intuitive insight on this property of the MMC loss: since the loss value C is proportional to the squared distance from the preset center µ ∗ y , the feature points with lower loss values are certain to locate in a smaller volume around the center.
Consequently, the feature points of the same class are encouraged to gather around the corresponding center, such that for each sample, there will be locally enough data in its neighborhood for robust learning (Schmidt et al., 2018).
The MMC loss value also becomes a reliable metric of the uncertainty on returned predictions.
Better exploiting model capacity.
Behind the simple formula, the MMC loss can explicitly monitor inter-class dispersion by the hyperparameter C MM , while enabling the network to concentrate on minimizing intra-class compactness in training.
Instead of repeatedly searching for an internal tradeoff in training as the center loss, the monotonicity of the supervisory signals induced by MMC can better exploit model capacity and also lead to faster convergence, as empirically shown in Fig. 3(a).
Avoiding the degradation problem.
The MMC loss can naturally avoid the degradation problem encountered in Wen et al.
(2016) when the center loss is not jointly used with the SCE loss, since the preset centers µ ∗ for MMC are untrainable.
In the test phase, the network trained by MMC can still return a normalized prediction with the softmax function.
More details about the empirical superiorities of the MMC loss over other previous losses are demonstrated in Sec. 4.
Remark 3.
In Appendix B.2, we discuss on why the squared-error form in Eq.
(8) is preferred compared to, e.g., the absolute form or the Huber form (Friedman et al., 2001) in the adversarial
[Figure]
setting.
We further introduce ﬂexible variants of the MMC loss in Appendix B.3, which can better adapt to various tasks
[Figure]
Remark 4.
Pang et al.
(2018) propose a Max-Mahalanobis linear discriminant analysis (MMLDA) method, which assumes the features to distribute as an MMD.
Due to the Gaussian mixture assumption, the training loss for the MMLDA method is obtained by the Bayes’ theorem as
[Equation]
Note that there is Σ i = 12 I in Eq.
(4) for the MMLDA loss, similar with the SCE loss.
Thus the
MMLDA method cannot explicitly supervise on the sample density and induce high-density regions in the feature space, as analyzed in Sec. 3.2.
Compared to the MMLDA method, the MMC loss introduces extra supervision on intra-class compactness, which facilitates better robustness.
E XPERIMENTS
In this section, we empirically demonstrate several attractive merits of applying the MMC loss.
We experiment on the widely used MNIST, CIFAR-10, and CIFAR-100 datasets (Krizhevsky & Hinton, 2009; LeCun et al., 1998).
Since the existing defenses can already provide satisfactory robustness on
MNIST (Madry et al., 2018; Raghunathan et al., 2018; Sinha et al., 2018), we mainly demonstrate the results on CIFAR-10 and CIFAR-100 in our experiments.
Our code is available at an anonymous link: http://
4. P ERFORMANCE ON THE CLEAN INPUTS
The network architecture applied is ResNet-32 with ﬁve core layer blocks (He et al., 2016).
Here we use MMC-10 to indicate the MMC loss with C MM = 10 , where C MM is assigned based on the cross-validation results in Pang et al.
The hyperparameters for the center loss, L-GM loss and the MMLDA method all follow the settings in the original papers (Pang et al., 2018; Wan et al., 2018; Wen et al., 2016).
The pixel values are scaled to the interval [0 , 1] .
For each training loss with or without the AT mechanism, we apply the momentum SGD (Qian, 1999) optimizer with the initial
The learning rate decays with a factor of 0 .
1 at 100 and 150 epochs, respectively.
When applying the AT mechanism (Madry et al., 2018), the adversarial examples for training are crafted by 10-steps targeted or untargeted PGD with (cid:15) = 8 / 255 .
In Fig. 3(a), we provide the curves of the test error rate w.r.t.
the training time.
Note that the MMC loss induces faster convergence rate and requires little extra computation compared to the SCE loss and its variants, while keeping comparable performance on the clean images.
In comparison, implementing the AT mechanism is computationally expensive in training and will sacriﬁce the accuracy on the clean images.
[Table]
(cid:15) =
[Table]
Perturbation (cid:15) = 16 /
[Table]
[Figure]
AT (SCE)
AT (MMC-10)
AT (MMC-100)
Sub s t
i t
u t e M o d
e
l
[Figure]
4. A DAPTIVE ATTACKS FOR THE MMC LOSS
As stated in Athalye et al.
(2018), only applying the existing attacks with default hyperparameters is not sufﬁcient to claim reliable robustness.
Thus, we apply the adaptive versions of existing attacks when evading the networks trained by the MMC loss (detailed in Appendix B.4).
For instance, the non-adaptive objectives for PGD are variants of the SCE loss (Madry et al., 2018), while the adaptive objectives are −L MMC ( z, y ) and L MMC ( z, y t ) in the untargeted and targeted modes for PGD, respectively.
Here y t is the target label.
To verify that the adaptive attacks are more effective than the non-adaptive ones, we modify the network architecture with a two-dimensional feature layer and visualize the PGD attacking procedure in Fig. 3(b).
The two panels separately correspond to two randomly selected clean inputs indicated by black stars.
The ten colored clusters in each panel consist of the features of all the 10,000 test samples in MNIST, where each color corresponds to one class.
We can see that the adaptive attacks are indeed much more efﬁcient than the non-adaptive one.
4. P ERFORMANCE UNDER THE WHITE - BOX ATTACKS
We ﬁrst investigate the white-box l ∞ distortion setting using the PGD attack, and report the results in
Table 1.
According to Carlini et al.
(2019), we evaluate under different combinations of the attacking parameters: the perturbation (cid:15) , iteration steps, and the attack mode, i.e., targeted or untargeted.
Following the setting in Madry et al.
(2018), we choose the perturbation (cid:15) = 8 / 255 and 16 / 255 , with the step size be 2 / 255 .
We have also run PGD-100 and PGD-200 attacks, and ﬁnd that the accuracy converges compared to PGD-50.
In each PGD experiment, we ran several times with different random restarts to guarantee the reliability of the reported results.
From the results in Table 1, the MMC loss can signiﬁcantly improve robustness even under the adaptive attacks.
When combining with the AT mechanism, the trained models have better performance under the attacks different from the one used to craft adversarial examples for training.
Then we investigate the white-box l 2 distortion setting.
We apply the C&W attack, where it has a binary search mechanism to ﬁnd the minimal distortion to successfully mislead the classiﬁer under the untargeted mode, or lead the classiﬁer to predict the target label in the targeted mode.
Following
[Table]
the suggestion in Carlini & Wagner (2017a), we set the binary search steps to be 9 with the initial constant c = 0 . 01 .
The iteration steps for each value of c are set to be 1,000 with the learning rate of 0 .
In the Part I of Table 2, we report the minimal distortions found by the C&W attack.
As expected, it requires much larger distortions to successfully evade the networks trained by MMC.
4. P ERFORMANCE UNDER THE BLACK - BOX ATTACKS
[Table]
As suggested in Carlini et al.
(2019), providing evidence of being robust against the black-box attacks is critical to claim reliable robustness.
We ﬁrst perform the transfer-based attacks using PGD and MIM.
Since the targeted attacks usually have poor transferability (Kurakin et al., 2018), we only focus on the untargeted mode in this case, and the results are shown in Fig.
We further perform the gradient-free attacks using the SPSA method and report the results in the Part II of Table 2.
To perform numerical approximations on gradients in SPSA, we set the batch size to be 128 , the learning rate is 0 . 01 , and the step size of the ﬁnite difference is δ = 0 .
01 , as suggested by Uesato et al.
We also evaluate under stronger
SPSA attacks with batch size to be 4096 and 8192 in Table 3, where the (cid:15) = 8 / 255 .
With larger batch sizes, we can ﬁnd that the accuracy under the black-box SPSA attacks converges to it under the white-box PGD attacks.
These results indicate that training with the MMC loss also leads to robustness under the black-box attacks, which veriﬁes that our method can induce reliable robustness, rather than the false one caused by, e.g., gradient mask (Athalye et al., 2018).
4. P ERFORMANCE UNDER THE GENERAL - PURPOSE ATTACKS
To show that our method is generally robust, we further test under the general-purpose attacks (Carlini et al., 2019).
We apply the Gaussian noise (Fawzi et al., 2016; Gilmer et al., 2019) and rotation transformation (Engstrom et al., 2019), which are not included in the data augmentation for training.
The results are given in the Part III of Table 2.
Note that the AT methods are less robust to simple transformations like rotation, as also observed in previous work (Engstrom et al., 2019).
In comparison, the models trained by the MMC loss are still robust to these easy-to-apply attacks.
4. E XPERIMENTS ON CIFAR-
In Table 4 and Table 5, we provide the results on CIFAR-100 under the white-box PGD and C&W attacks, and the black-box gradient-free SPSA attack.
The hyperparameter setting for each attack is the same as it on CIFAR-10.
Compared to previous defense strategies which also evaluate on
CIFAR-100 (Pang et al., 2019; Mustafa et al., 2019), MMC can improve robustness more signiﬁcantly, while keeping better performance on the clean inputs.
Compared to the results on CIFAR-10, the
[Table] [Table]
(cid:15) =
[Table]
averaged distortion of C&W on CIFAR-100 is larger for a successful targeted attack and is much smaller for a successful untargeted attack.
This is because when only the number of classes increases, e.g., from 10 to 100, it is easier to achieve a coarse untargeted attack
[Table]
but harder to make a subtle targeted attack.
Note that in Table
[Table]
we also train on the ResNet-110 model with eighteen core block layers except for the ResNet-32 model.
The results show that MMC can further beneﬁt from deep network architectures and better exploit model capacity to improve robustness.
Similar properties are also observed in previous work when applying the AT methods (Madry et al., 2018).
In contrast, as shown in Table 5, the models trained by SCE are comparably sensitive to adversarial perturbations for different architectures, which demonstrates that SCE cannot take full advantage of the model capacity to improve robustness.
This veriﬁes that MMC provides effective robustness promoting mechanism like the AT methods, with much less computational cost.
C ONCLUSION
In this paper, we formally demonstrate that applying the softmax function in training could potentially lead to unexpected supervisory signals.
To solve this problem, we propose the MMC loss to learn more structured representations and induce high-density regions in the feature space.
In our experiments, we empirically demonstrate several favorable merits of our method: (i) Lead to reliable robustness even under strong adaptive attacks in different threat models; (ii) Keep high performance on clean inputs comparable TO SCE; (iii) Introduce little extra computation compared to the SCE loss; (iv)
Compatible with the existing defense mechanisms, e.g., the AT methods.
Our analyses in this paper also provide useful insights for future work on designing new objectives beyond the SCE framework.
A P ROOF
In this section, we provide the proof of the theorems proposed in the paper.
A. P ROOF OF T HEOREM
According to the deﬁnition of sample density
[Equation]
we separately calculate ∆ N and Vol (∆ B ) .
Since L g-SCE ∼ p k, ˜ k
( c ) for the data points in D k, ˜ k , recall that ∆ B = { z ∈ R d |L g-SCE ∈ [ C, C + ∆ C ] } , then there is
[Equation]
Now we calculate Vol (∆ B ) by approximating it with Vol (∆ B y, ˜ y ) .
We ﬁrst derive the solution of
L y, ˜ y
= C .
For simplicity, we assume scaled identity covariance matrix, i.e., Σ i =
σ i
I , where σ i > 0 are scalars.
Then ∀ i, j ∈ [ L ] , c is any constant, if σ i (cid:54) =
σ j , the solution of h i − h
j = c is a ( d − 1) -dimensional
hypersphere embedded in the d -dimensional space of the feature z : (cid:107)
z − M i,j (cid:107)
= B i,j − c σ i − σ j , where M i,j =
[Equation]
Note that each value of c corresponds to a speciﬁc contour, where M i,j and B i,j can be regraded as constant w.r.t.
c .
When B i,j < ( σ i − σ j ) − 1 c , the solution set becomes empty.
Specially, if σ i = σ j = σ , the hypersphere-shape contour will degenerate to a hyperplane: z (cid:62) ( µ i − µ j ) = 12 (cid:2) (cid:107) µ i (cid:107) 22 − (cid:107) µ j (cid:107) 22 + σ − 1 ( B j − B
i + c ) (cid:3) .
For example, for the SCE loss, the solution of the contour is z (cid:62) ( W i − W j ) =
b j − b i + c .
For more general Σ i , the conclusions are similar, e.g., the solution in Eq.
(12) will become a hyperellipse.
Now it easy to show that the solution of L y,
˜ y
= C when y = k, ˜ y =
˜
k is the hypersphere:
[Equation]
According to the formula of the hypersphere surface area (Loskot & Beaulieu, 2007), the volume of ∆ B y, ˜
y is
[Equation] [Equation]
where Γ( · ) is the gamma function.
Finally we can approximate the sample density as
[Equation]
A. P ROOF OF T HEOREM
Similar to the proof of Theorem 1, there is
[Equation]
Unlike for the g-SCE, we can exactly calculate Vol (∆ B ) for the MMC loss.
Note that the solution of
L MMC =
C is the hypersphere:
[Equation]
[Equation]
[Equation]
According to the formula of the hypersphere surface area (Loskot & Beaulieu, 2007), we have
[Equation]
where Γ( · ) is the gamma function.
Finally we can obtain the sample density as
[Equation]
B T ECHNICAL DETAILS
In this section, we provide more technical details we applied in our paper.
Most of our experiments are conducted on the NVIDIA DGX-1 server with eight Tesla P100 GPUs.
B. G ENERATION ALGORITHM FOR THE M AX -M AHALANOBIS CENTERS
We give the generation algorithm for crafting the Max-Mahalanobis Centers in Algorithm 1, proposed by Pang et al.
Note that there are two minor differences from the originally proposed algorithm.
First is that in Pang et al.
they use C = (cid:107) µ i (cid:107) 22 , while we use C MM = (cid:107) µ i (cid:107) 2 .
Second is that we denote the feature z ∈ R d , while they denote z ∈ R p .
The Max-Mahalanobis centers generated in the low-dimensional cases are quite intuitive and comprehensible as shown in
Fig.
For examples, when L = 2 , the Max-Mahalanobis centers are the two vertexes of a line segment; when L = 3 , they are the three vertexes of an equilateral triangle; when L = 4 , they are the four vertexes of a regular tetrahedron.
Algorithm
1 GenerateMMcenters
Input: The constant C MM , the dimension of vectors d and the number of classes L .
( L ≤ d + 1 )
Initialization: Let the L mean vectors be µ ∗ 1 = e 1 and µ ∗ i =
d , i (cid:54) = 1 .
Here e 1 and 0 d separately denote the ﬁrst unit basis vector and the zero vector in R d . for i = 2 to L do for j = 1 to i − 1 do µ ∗ i ( j ) = − [1 + (cid:104) µ ∗ i , µ ∗ j (cid:105) ·
( L − 1)] / [ µ ∗ j ( j ) · ( L − 1)] end for µ ∗ i ( i ) =
(cid:112) 1 − (cid:107) µ ∗ i (cid:107) 2end for for k = 1 to L do µ ∗ k = C MM · µ ∗ k end for Return: The optimal mean vectors µ ∗ i , i ∈ [ L ] .
B. W HY THE SQUARED - ERROR FORM IS PREFERRED
In the feature space, penalizing the distance between the features and the preﬁxed centers can be regarded as a regression problem.
In the MMC loss, we apply the squared-error form as (cid:107) z − µ ∗ y (cid:107) 22 .
Other substitutes could be the absolute form (cid:107)
z − µ ∗ y (cid:107) 2 or the Huber form.
As stated in Friedman et al.
(2001), the absolute form and the Huber form are more resistant to the noisy data (outliers) or the misspeciﬁcation of the class labels, especially in the data mining applications.
However, in the classiﬁcation tasks that we focus on in this paper, the training data is clean and reliable.
Thus the squared-error form can lead to high accuracy with faster convergence rate compared to other forms.
Furthermore, in the adversarial setting, the adversarial examples have similar properties as the outliers.
When we apply the AT mechanism in the training procedure, we expect the classiﬁers to pay more attention to the adversarial examples, i.e., the outliers.
Note that this goal is the opposite of it in the data mining applications, where outliers are intended to be ignored.
Therefore, due to the sensitivity to the outliers, the squared-error form can better collaborate with the AT mechanism to improve robustness.
Besides, the MMC loss can naturally perform stronger AT mechanism without additional regularizer term.
Speciﬁcally, let x be the clean input, x ∗ be the adversarial example crafted based on x , then in the adversarial logit pairing (ALP) method (Kannan et al., 2018), there is an extra regularizer except for SCE as:
[Equation]
When adding x ∗ as an extra training point for MMC, then the MMC loss will minimize[-(cid:107) z ( x ) − µ ∗ y (cid:107) 
-]
[Equation]
22 , which is an upper bound for 12 (cid:107) z ( x ) − z ( x ∗ ) (cid:107) 22 .
Thus performing naive adversarial training (Goodfellow et al., 2015; Madry et al., 2018) with MMC is equivalent to performing stronger adversarial training variants like ALP.
As analyzed above, the squared-error form in the MMC loss can accelerate the convergence of the AT mechanism, since the objective is sensitive to the crafted adversarial examples.
B. V ARIANTS OF THE MMC LOSS
In the MMC loss, we encourage the features to gather around the preset Max-Mahalanobis (MM) centers µ ∗ = { µ ∗ l } l ∈ [ L ] , which leads to many attractive properties.
However, this ’hard’ supervision, which induces quite an orderly feature distribution may beyond the reach of the model capability, especially when the classiﬁcation tasks themselves are already challenging to learn, e.g., ImageNet (Deng et al., 2009).
Therefore, we propose potential variants of the MMC loss that could probably solve the problem and make our method more adaptable.
We leave the experimental investigations as future work.
Note that the MMC loss can be regarded as minimizing the negative log likelihood (NLL) of − log( P ( z | y )) , where the conditional feature distribution is modeled as z | y ∼ N ( µ ∗ y , I ) .
As described above, this distribution model may not be easy to learn by the DNNs in some cases.
Thus, we construct a softer model: z | y, µ y ∼ N ( µ y , I ) and µ y ∼ N ( µ ∗ y , αI ) , where α > 0 is a scalar.
Here we give the feature center µ y a prior distribution, while the prior is centered at µ ∗ y .
Intuitively, we relax the constraint that the features have to gather around µ ∗ y .
Instead, we encourage the features to gather around a substitute µ y , while µ y should be in the vicinity of µ ∗ y .
In the training, we minimize the joint NLL of − log( P ( z, µ y | y ))
= − log( P ( z | y, µ y ))
− log( P ( µ y )) , which is equivalent to minimize the what we call elastic Max-Mahalanobis center (EMC) loss as:
[Equation]
Here µ = { µ l } l ∈ [ L ] are simply extra trainable parameters, the prior variance α is a hyperparameter.
When α → 0 , the EMC loss degenerates to the MMC loss.
Note that although µ ∗ l are all on the hypersphere { z ∈ R d |(cid:107) z (cid:107) =
C MM } , the support sets of µ l are the entire feature space R d .
Further improvement can be made w.r.t.
the MM centers µ ∗ .
An implicit assumption behind the generation process of µ ∗ is that any two classes are mutually independent.
This assumption could be approximately true for MNIST and CIFAR-10, but for more complex datasets, e.g., CIFAR-100 or
ImageNet, this assumption may not be appropriate since there are structures in the relation among classes.
These structures can usually be visualized by a tree.
To solve this problem, we introduce the hierarchical Max-Mahalanobis (HM) centers µ H
= { µ H l } l ∈
[ L ] , which adaptively craft the centers [Figure] according to the tree structure.
Speciﬁcally, we ﬁrst assign a virtual center (i.e., the origin) to the root node.
For any child node n c in the tree, we denote its parent node as n p , and the number of its brother nodes as L c .
We locally generate a set of MM centers as µ ( s,L c ) =
GenerateMMcenters ( C s , d, L c ) , where s is the depth of the child node n c , C s is a constant with smaller values for larger s .
Then we assign the virtual center to each child node of n p from µ n p + µ ( s,L c ) , i.e., a shifted set of crafted
MM centers, where µ n p is the virtual center assigned to n p .
If the child node n c is a leaf node, i.e., it correspond to a class label l , then there is µ H l = µ n c .
For example, in the CIFAR-100 dataset, there are 20 superclasses, with 5 classes in each superclass.
We ﬁrst craft 20 MM centers as µ (1 , 20) =
GenerateMMcenters ( C 1 , d, 20) and 5 MM centers as µ (2 , 5) =
GenerateMMcenters ( C 2 , d, 5) , where
C 2 (cid:28) C 1 .
Note that µ (2 , 5) could be different for each superclass, e.g., by a rotation transformation.
Then if the label l is the j -th class in the i -th superclass, there is µ H l = µ (1 , 20) i + µ (2 , 5) j .
B. A DAPTIVE OBJECTIVES AND THE INDUCED ATTACKING MECHANISMS
We apply the adaptive versions of existing attacks when evading the networks trained by the MMC loss.
We separately design two adaptive adversarial objectives L Ada to minimize under the untargeted mode: L un , 1 Ada = −L MMC ( z, y ) ; L un , 2 Ada =
L MMC ( z, ˜ y )
−L MMC ( z, y ) , and under the targeted mode:
L tar , 1 Ada =
L MMC ( z, y t ) ; L tar , 2 Ada =
L MMC ( z, y t ) −L MMC ( z, y ) , where y t is the targeted label,
˜ y is generally the highest predicted label except for y as deﬁned in Sec. 3.2.
These objectives refer to previous work by Carlini & Wagner (2017a;b).
Speciﬁcally, the adaptive objectives L tar , 1 Ada and L un , 1 Ada are used in the
PGD, MIM and SPSA attacks, while the objectives L tar , 2 Ada and L un , 2 Ada are used in the C&W attacks.
In Fig.
6, we demonstrate the attacking mechanisms induced by different adaptive adversarial objectives.
Note that we only focus on the gradients and ignore the speciﬁc method which implements the attack.
Different adaptive objectives are preferred under different adversarial goals.
For examples, when decreasing the conﬁdence of the true label is the goal, L un , 1 Ada is the optimal choice; in order to mislead the classiﬁer to predict an untrue label or the target label, L un , 2 Ada and L tar , 2 Ada are the optimal choices, respectively.
Sometimes there are additional detectors, then the adversarial examples generated by L tar , 1 Ada could be assigned to the target label with high conﬁdence by the classiﬁers.
B. R ELATED WORK IN THE FACE RECOGNITION AREA
There are many previous work in the face recognition area that focus on angular margin-based softmax (AMS) losses (Liu et al., 2016; 2017; Liang et al., 2017; Wang et al., 2018; Deng et al., 2019). They mainly exploit three basic operations: weight normalization (WN), feature normalization (FN), and angular margin (AN). It has been empirically shown that WN can beneﬁt the cases with unbalanced data (Guo & Zhang, 2017); FN can encourage the models to focus more on hard examples (Wang et al., 2017); AN can induce larger inter-class margins and lead to better generalization in different facial tasks (Wang et al., 2018; Deng et al., 2019). However, there are two critical differences between our MMC loss and these AMS losses:
Difference one: The inter-class margin • The AMS losses induce the inter-class margins mainly by encouraging the intra-class compactness, while the weights are not explicitly forced to have large margins (Qi & Zhang, 2018). • The MMC loss simultaneously ﬁxes the class centers to be optimally dispersed and encourages the intra-class distribution to be compact. Note that both of the two mechanisms can induce inter-class margins, which can ﬁnally lead to larger inter-class margins compared to the AMS losses.
Difference two: The normalization
• The AMS losses use both WN and FN to exploit the angular metric, which makes the normalized features distribute on hyperspheres. The good properties of the AMS losses are at the cost of abandoning the radial degree of freedom, which may reduce the capability of models.
• In the MMC loss, there is only WN on the class centers, i.e., (cid:107) µ ∗ y (cid:107) =
C MM , and we leave the degree of freedom in the radial direction to keep model capacity. However, note that the MMC loss (cid:107) z − µ ∗ y (cid:107) 22 ≥ ( (cid:107) z (cid:107) 2 − C MM ) 2 is a natural penalty term on the feature norm, which encourage (cid:107) z (cid:107) 2 to not be far from C MM . This prevents models from increasing feature norms for easy examples and ignoring hard examples, just similar to the effect caused by FN but more ﬂexible.