Training Robust Classifiers (Part 1)


In the previous post, we have seen that classifiers are often vulnerable to small perturbations of their inputs. Although these perturbations (also known as adversarial examples) usually do not confuse humans, they can entirely change the prediction of an otherwise accurate classifier. In this blog post and the next one, we will see how to train classifiers that are significantly more robust to such perturbations.

The Goal: (Adversarially) Robust Generalization

When studying adversarial examples, it is important to remember that we implicitly change our measure of performance. Normally, we judge the performance of a classifier (mapping from input to label ) by computing the average loss under a data distribution :

If this average loss is small, we say that we have learned a good classifier.

In contrast, robust classification calls for a more stringent measure of performance. We now allow an adversary to perturb the sample before feeding it to our classifier . Since we are primarily interested in perturbations that do not change the true label, we limit the adversary by restricting it to a pre-defined perturbation set . This leads to the following quantity:

It is important to note that a classifier with small “standard” loss (1) is not necessarily a good classifier under the robust loss (2). After all, the guarantee (1) makes no explicit statement about the perturbation set . A classifier could have small “standard” loss (1) and correctly classify most of the inputs in , while still having a large robust loss when measured as in (2). This is because we count as misclassified in (2) as long as there is at least one in that is misclassified. So we should not be surprised when “standard” classifiers - which aim to minimize (1) - turn out to be non-robust: we never trained them to be robust in the first place! The widespread vulnerability to small perturbations is thus hardly an unexpected “failure” of standard classifiers.

Another key aspect of the robust loss (2) is that it does not involve a specific method for constructing perturbations . So if we can find a classifier with small robust loss, we can be sure that the classifier is robust to any perturbation in the set . This is an important difference to prior work, where the focus was often on robustness to specific attack methods (e.g., FGSM or JSMA). While specialized defenses do give strong robustness to these specific attacks, this has also led to “arms races” in earlier work (link1, link2, link3, link4) where such specialized defenses were later circumvented by applying a different attack to them. In contrast, objective (2) gives a universal robustness guarantee that applies to all methods for crafting perturbations in .

Now that we have set our sights on objective (2), there are two key questions:

  1. What is a good perturbation set ?
  2. How can we get a robust classifier for the chosen perturbation set ?

Both issues are the subject of active research. We will present our take on perturbation sets at a later time and focus on the second question (optimization) here. To be concrete, we will work with the -ball as constraint set P since it has received a lot of attention in image classification lately. While -perturbations certainly do not capture all aspects of image similarity, they are commonly used as a natural baseline. After all, a fully robust classifier needs to be invariant to at least small -bounded perturbations. Hence -robustness is a necessary (but not sufficient) perturbation set here. In a later blog post, we will see that the same optimization methodology largely applies to other perturbation sets as well.

Robust Optimization (a.k.a. Adversarial Training)

In the previous section we have seen that a classifier with small robust loss as in (2) would be useful. How can we learn such a classifier? For the standard loss (1), the prevalent learning methods are based on empirical risk minimization (ERM). So a natural approach in the adversarial setting is to use an analogous “robustified” variant of ERM. In particular, our goal is to find model parameters so that the corresponding classifier has a small empirical loss even when an adversarial perturbation is applied:

Min-max problems of this form have a long history going back to at least the work of Abraham Wald from the 1940s (link). Moreover, the field of robust optimization has studied min-max problems over the past few decades (link). In the following, we will discuss how to solve such problems in the context of neural networks.

At a first glance, it might be unclear how to solve Problem (3). The optimization problem consists of both an outer minimization and an inner maximization. In addition, the inner maximization is non-concave, and the outer minimization is non-convex. To tackle this problem, it turns out to be useful to split the overall problem into an outer minimization and inner maximization, as we will describe in the next two sections.

Outer Minimization

Without the inner maximization, Problem (3) is exactly the same problem as training a regular classifier. While this is a non-convex problem for neural networks, SGD still tends to perform well in that setting. Hence it is also a natural starting point for the outer minimization part of the robust ERM problem (3). In order to run SGD, we need to compute gradients of the robust loss

Note that is itself an optimization problem, so we can’t simply run backpropagation with the standard building blocks of a neural network. Fortunately, as we mentioned, the optimization community has long figured out how to compute gradients for such min-max problems. The theoretical motivation here comes from Danskin’s Theorem (link). Informally speaking, Danskin’s Theorem tells us that we can obtain a gradient of w.r.t. by finding a constrained maximizer of the inner maximization problem (4). We can then use this maximizer as our actual data point and compute the gradient at , i.e.,

There are technical conditions for Danskin’s Theorem, but convexity is not one of them. So if we can find an optimal solution of the inner maximization problem, we can also get a gradient for the outer minimization problem and run SGD.

Inner Maximization

We now consider the inner maximization problem. Note that keeping fixed and finding a maximizer of the robust loss (4) corresponds exactly to the the problem of optimally attacking a given classifier. That is, the classifier can be fooled with a point in the perturbation set if and only if the the maximizer of is an adversarial example. This connection shows an important duality between attacking a classifier and training a robust classifier: if we have a good attack, we also have a method for finding good gradients of the robust loss . So in order to train a classifier minimizing (2), we should train against the strongest adversary possible (i.e., within a feasible computational budget).

Overall, the robust optimization perspective suggests the following procedure for training a robust classifier:

  1. Sample a data point , .
  2. Compute the maximizer of the robust loss .
  3. Compute the gradient .
  4. Update with the gradient .
  5. Repeat Steps 1 - 4 until convergence.

In deep learning, this procedure amounts to a variant of standard training in which, instead of training on unmodified data points (as SGD normally would), we first compute adversarial perturbations for all the training points in the current batch (Step 2). Then we apply the gradient to our model parameters as usual, but with respect to these perturbed points instead of the original ones (Steps 3-4). In the deep learning community, this approach has become known as “adversarial training”, but it is worth to remember that methods such as this one have a long history in robust optimization.

Of course, the important question now is whether this theoretical perspective is predictive of the actual performance in practice. One reason to be concerned is that robust optimization (i.e., adversarial training) had already been employed in prior work, but did not lead to truly robust models there (even on simple datasets such as MNIST). It turns out that the robust optimization framework can indeed produce models that are robust in practice. But the key to success lies in the details of how to exactly execute the robust optimization paradigm. We will discuss this aspect in the next post.

Subscribe to our RSS feed.