{'fraction_non_alphanumeric': 0.02938068920676203, 'fraction_numerical': 0.008452535760728219, 'mean_word_length': 4.755144995322731, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Single-Step Adversarial Training for Semantic Segmentation

Even though deep neural networks succeed on many different tasks including semantic segmentation, they lack on robustness against adversarial examples. To counteract this exploit, often adversarial training is used. However, it is known that adversarial training with weak adversarial attacks (e.g. using the Fast Gradient Method) does not improve the robustness against stronger attacks. Recent research shows that it is possible to increase the robustness of such single-step methods by choosing an appropriate step size during the training. Finding such a step size, without increasing the computational effort of single-step adversarial training, is still an open challenge. In this work we address the computationally particularly demanding task of semantic segmentation and propose a new step size control algorithm that increases the robustness of single-step adversarial training. The proposed algorithm does not increase the computational effort of single-step adversarial training considerably and also simplifies training, because it is free of meta-parameter. We show that the robustness of our approach can compete with multi-step adversarial training on two popular benchmarks for semantic segmentation.


Introduction
Due to their great performance, deep neural networks are increasingly used on many classification tasks. Especially in vision tasks, like image classification or semantic segmentation, deep neural networks have become the standard method. However, it is known that deep neural networks are easily fooled by adversarial examples [18], i.e. very small perturbations added to an image such that neural networks classify the resulting image incorrectly. Interestingly, adversarial examples can be generated for multiple machine learning tasks, including image classification and semantic segmentation, and the perturbations are most of the time so small that humans do not even notice the changes (e.g. see fig. 1). This phenomenon highlights a significant discrepancy of the human vision system (a) Clean image from Cityscapes [3].
(b) Prediction of the clean image.
(d) Prediction of the adversarial example. and deep neural networks, and highlights a possibly crucial vulnerability of the latter. This fact should be taken into consideration, especially in safety critical applications like autonomous driving cars [20].
To increase the robustness of deep neural networks, progress along two different lines of research could be observed in the last years: provable robustness and adversarial training. Provable robustness has the goal to certify that the prediction does not change in a local surrounding for most inputs. This approach has the advantage of yielding robustness guarantees, but it is not that scalable to complex deep neural networks yet [15,21], or it severely affects the inference time [2] which is problematic for many applications. In contrast to this theoretical viewpoint, the idea of adversarial training is more empirically driven: create adversarial examples during training and use them as training data [5,13], this procedure can be interpreted as an efficient realization of a robustified loss function which minimizes the error simultaneously for potentially disturbed data [16]. Adversarial training has the advantage that it is universally applicable, and often results in high robustness albeit this holds empirically and w.r.t. a specific norm. Only reject options have the potential to improve the robustness w.r.t. different norms [17].
An optimization of the inner loop of the adversarial loss function is often addressed by numeric methods which rely on an iterative perturbation of the input in the direction of its respecting gradient. But this leads to multiple forward and backward passes through the deep neural network and therefore highly increases the training time. To reduce the computational effort of adversarial training Goodfellow et al. used the information of just a single gradient for computing the adversarial examples [5]. But this kind of single-step adversarial training can be too weak and it has been observed that overfitting can take place, i.e. the specific adversarial is classified correctly, but not its immediate environment. In particular, it is not robust against multi-step attacks [13]. Recent research discovered that this overfitting is caused by using a static step size while creating the adversarial examples for adversarial training [9]. To overcome this, the authors of [9] propose a method to find an ideal step size by evaluating equidistant points in the direction of the gradient. But this algorithm is in worst case as expensive as multi-step adversarial training.
Differently to most of the previous research on adversarial robustness, we will focus on adversarial training for semantic segmentation in this work. The task of semantic segmentation is to assign every pixel of the input image a corresponding class. Because semantic segmentation needs to address localization and semantic simultaneously, it is a more complicated task than image classification [12]. Consequently, the models for semantic segmentation are generally complex, and therefore the computational effort to train such models is in principal very high. Since adversarial training also negatively affects the training time, our goal is to find a computationally efficient method which at the same time increases the robustness of semantic segmentation models effectively.
For this purpose, we extend the idea of robust single-step adversarial training. On the one hand, we investigate single-step adversarial training for semantic segmentation as a relevant and challenging application problem for deep learning, and we demonstrate that it shares the problem of overfitting and limited robustness towards multi-step attacks with standard classification problems. On the other hand, we demonstrate that a careful selection of the step size can mitigate this problem insofar as even random step sizes improve robustness. We propose an efficient parameterless method to choose an optimum step size, which yields robustness results which are comparable to multi-step adversarial training for two popular benchmarks from the domain of image segmentation, while sharing the efficiency of single-step approaches.

Adversarial Training
Adversarial training for a classical image classification task tries to solve the following robust optimization problem [16]: given a paired sample (x, y) consisting of an input sample x ∈ X ⊂ [0, 1] H×W ×C and an associated label y ∈ Y ⊂ {1, . . . , M }, where H, W , C and M are the height, the width, the number of color channels and the number of classes, respectively, let denote the loss function of a deep neural network f θ : X → [0, 1] M , robust learning aims for the weights θ with where E and B(0, ε) denote the expected value and a sphere at origin with radius ε, respectively. The sphere is dependent on a chosen distance metric. In the context of adversarial examples most often L 0 , L 2 and L ∞ are considered.
In this paper we focus only on L ∞ . Because the loss function is highly nonlinear and non-convex even solving the inner maximization in eq. (1) is considered intractable [8,19]. Therefore, the maximization problem is often approximated by crafting adversarial examples, such that the optimization of adversarial training changes to where the adversarial examples x adv ∈ X adv ⊂ [0, 1] H×W ×C are generated by a chosen adversarial attack, such that x − x adv ∞ ≤ ε holds. To guarantee the classification accuracy on the original clean samples usually x adv is randomly set to be a clean sample or an adversarial example [5]. For crafting adversarial examples while training, most often gradient based methods, like the Fast Gradient Sign Method or the Basic Iterative Method, are used.
Fast Gradient Sign Method The Fast Gradient Sign Method (FGSM) is a single-step adversarial attack which is a particularly easy and computationally cheap gradient based method, because it uses just a single gradient for calculating the adversary noise [5]. If a step size ε is given, an adversarial example is determined by Basic Iterative Method The Basic Iterative Method (BIM) is a multi-step generalization of the FGSM [10]. Instead of evaluating just one gradient, the BIM uses n gradients iteratively, to reach a stronger adversarial example. Given a maximum perturbation ε, a number of iterations N and a step size α, an adversarial example created with BIM is given iteratively by Where thep = Clip x,ε (p)-Function projects p into the ε-neighbourhood of x, such that p − x ∞ ≤ ε.

Restrictions of Single-step Adversarial Training
To generate adversarial examples while training, Goodfellow et al. chose the FGSM as a computationally cheap adversarial attack [5]. It was shown that models trained with such a single-step adversarial training are not robust against multi-step attacks [13]. To train robust models, multi-step adversarial training is commonly used. Since multi-step approaches require multiple forward and backward passes through the deep neural network, training a robust model becomes computationally very intensive.
To minimize the computational effort while training, one line of work tries to increase the robustness of single-step adversarial training. Wong et al. analyzed the robustness of single-step adversarial training epoch-wise and observed that the robustness against BIM increases in the beginning during training, but decreases after some epochs [22]. This observation is called catastrophic overfitting. To overcome this phenomenon Wong et al. added random noise to the input before using the FGSM for adversarial training and also added early-stopping by tracking the multi-step robustness of small batches. A few further approaches follow this line of research [1,11].
Because these methods need to calculate more than one gradient at some point, they are computationally inefficient. Kim et al. showed empirically that the static step size for generating the adversarial examples constitute a reason why single-step adversarial training is not robust [9]. Single-step adversarial examples which are generated by a fixed step size have a fixed distance from their original data points. When training on such samples as well as on the original data points, there is no incentive of the loss function to predict the interval in between these extremes correctly or to provide a monotonic output in this region. This can lead to catastrophic overfitting as displayed in fig. 2, i.e. the original data and the chosen adversarial examples are correct, but not the region in between. Multi-step adversarial attacks iteratively use small step sizes, and therefore are able to find these areas of non-monotonicity, such that single-step adversarial training is not robust against multi-step attacks. To overcome this problem, Kim et al. proposed to test a range of different step sizes by equidistant sampling in the direction of the gradient and to choose the smallest step size which leads to a false prediction for generating the adversarial example [9]. Since this approach aims for a minimum step size to generate an adversarial sample, we can expect monotonicity of the network output in between, at least it is guaranteed that no closer adversarials can be found in the direction of the gradient. Hence overfitting seems less likely in such cases, as is confirmed by the experimental finding presented in [9].
Yet, the sampling strategy which is presented in [9] requires several forward passes through the network and is thus in worst case as demanding as multi-step approaches. In the following, we propose an approximate analytic solution how to compute a closest adversarial, which leads to an efficient implementation of this robust step size selection strategy.

Choosing the Step Size for Image Classification
To explain the idea behind our step size control algorithm, we first start looking at image classification. We are interested in an efficient analytic approximation which yields the closest adversarial example, i.e. a closest pattern where the classification changes. The deep neural network is given as a function f θ : X → [0, 1] M , where the output of the deep neural network f θ (x) is computed using the softmax function. The inputs to the softmax z(x) are called logits. We define the gain function g : X × Y → R as where z i (x) is the logit value of class i. The gain function in eq. (5) has the property that For given (x, y) a close adversarial example can be found at the boundary between a correct and an incorrect prediction, which holds if g(x adv , y) = 0.
Using the update rule of FGSM in eq. (3) on the gain function, we create an adversarial example by For estimating the step size ε, we linearly approximate the gain function g with a Taylor approximation Combining eq. (7), eq. (8) and eq. (9) results in which we can solve for the step size ε: Notice, the idea of the above step size control is the same as doing one step of Newton's approximation method for finding the zero crossings of a function. We therefore call our approach Fast Newton Method. Contrary to the classical solution of robust optimization, we use an approximation of the closest adversarial for training. This has two effects: on the one hand, we expect monotonicity of the loss in between, or a sufficient distance from 0. Hence a network which classifies x and the closest adversarial correctly likely classifies the enclosed interval in the same way, avoiding catastrophic overfitting. On the other hand, we do not consider any predefined radius; rather we use the smallest radius that includes an adversarial example. Using these adversarial examples for training, iteratively increases the radius of the sphere, and consequently the distance where adversarials can be found.

Robust Semantic Segmentation
The above mentioned results were presented in the context of image classification. In this work we want to concentrate on semantic segmentation. It is already known that deep neural networks for semantic segmentation are also vulnerable against adversarial examples [14,23], but only few approaches address the question how to efficiently implement robust training for image segmentation tasks. As far as we know, there is only one work investigating the impact of multi-step adversarial training on semantic segmentation [24]. First, we formalize the learning objective for robust semantic segmentation. Because semantic segmentation determines the class of each single pixel of an image, semantic segmentation could be interpreted as multiple pixel-wise classifications. To predict all the pixels at the same time the deep neural network function f θ : X → [0, 1] H×W ×M has increased output dimension. The set of labels are given by Y ⊂ {1, . . . , M } H×W . Robust learning on semantic segmentation tries to optimize for the weights θ, where f θ,j (x) and y j are the prediction and the label of the j-th pixel, respectively. To find the weights for all the pixel-wise predictions simultaneously, the losses of the pixel-wise predictions are averaged. Adversarial training on semantic image segmentation approximates the min-max loss by the following term: where x adv ∈ X adv constitutes a suitable image with x − x adv ∞ ≤ ε, which plays the role of an adversarial in the sense that it leads to an error of the segmented image for a large number of pixels. Yet, unlike for scalar outputs, it is not clear what exactly should be referred to by an adversarial: we can aim for an input x adv such that all output pixels change, or, alternatively, approximate this computationally extensive extreme by an efficient surrogate, as we will introduce in the following.

Choosing the Step Size for Semantic Segmentation
Initially, we treat each pixel as a separate output. An adversarial corresponds to an input such that one specific output pixel changes. For this setting, the gain function from eq. (5) becomes: where z j,i (x) is the logit value of the j-th pixel of class i. To find a close adversarial example x adv which changes all (or a large number of) pixels, each pixel-wise output should be at the boundary between a correct and an incorrect prediction. This holds if g j (x adv , y j ) = 0, ∀j ∈ {1, . . . , HW }.
Using our results from sec. 3.1, we obtain a different step size ε j for every pixel, hence a possibly different adversarial x (j) adv for each pixel-wise prediction. A common adversarial example x adv which approximately suits for all pixel-wise predictions in the same time, could be chosen as the average term But this procedure requires the computation of HW different gradients ∇ x g j (x, y j ) for j = 1, . . . , HW which is computational too expensive to work with.
As an alternative, we can refer to adversarial examples as images for which a number of pixels change the segmentation assignment. In this case we consider the pixel-wise predictions at the same time from the beginning by using the average of the gain functions (rather than the average of the specific pixel-wise adversarials). A close adversarial example in this sense is then given if 1 HW HW j=1 g j (x adv , y j ) = 0.
Defining the averaged gain function asḡ(x, y) = 1 HW HW j=1 g j (x, y j ) and using our method from sec. 3.1 results in a single step size such that the update rule for finding an adversarial example becomes Of course using the averaged gain function for calculating the step size ε in eq. (18) leads to a more loose approximation, but as a trade off this method does not increase the computational effort compared to adversarial training with the FGSM considerably, because we also calculate just one gradient.

Implementation
Datasets To evaluate our approach, we use the datasets Cityscapes [3] and PASCAL VOC [4]. Cityscapes contains 2975, 500 and 1525 colored images of size 1024 × 2048 for training, validation and testing, respectively. The labels assign most pixels one of 19 classes, where some areas are not labeled. PASCAL VOC originally includes 1464, 1499 and 1456 differently sized images for training, validation and testing, respectively. Later the training set was increased to 10582 images [6]. Including the background class, the pixels are labeled as one of 21 classes. Like in Cityscapes there are also some areas not labeled, such that we limit our loss and gain function for both datasets to the labeled pixels. We always normalise the color channels in the range of [0, 1].
Model As base model we chose the popular PSPNet50 architecture from [25] with a slight modification. Instead of using ResNet50 we work with the improved ResNet50v2 as fundamental pretrained network [7]. For the training parameters we follow the paper [25] using SGD with a momentum of 0.9. The learning rate decays polynomially with a base learn rate of 0.01 and power 0.9. We use a batchsize of 16 and also include L 2 weight decay of 10 −4 . However, for a better comparison to different models, we do not apply the auxiliary loss from [25]. To further increase the variation of the dataset, the data is randomly horizontally flipped, resized between 0.5 and 2, rotated between −10 and 10 degrees, and additionally randomly blurred. Afterwards, we randomly crop the images to a size of 712 × 712 and 472 × 472 for Cityscapes and PASCAL VOC, respectively. For evaluation, we will compare the robustness of the following models: where the parameters of the BIM Model are taken from [24]. For adversarial training the input is randomly chosen either a clean data sample or an adversarial example, each with probability of 0.5.
Evaluating the Robustness We measure the performance on the clean and the adversary data with mean IoU [4]. The mean IoU is a standard measure for semantic segmentation. It is used over the standard accuracy per Pixel, because it better represents the desired accuracy in case of differently sized objects.
For the empirical robustness evaluation we attack each model with FGSM and BIM. For both attacks we vary the attack radius ε from 0 to 0.04, such that we receive one robustness curve for each model and attack. As trade off between computational time and attack strength, we use BIM with N = 10 iterations. We chose the step size α as small as possible, such that the maximum perturbation rate of ε = 0.04 is still reachable. Hence, we use α = 0.004 as step size for BIM.

Results on Cityscapes
Single-Step Robustness In fig. 3(a) Fig. 3(b) shows the robustness of the trained models against attacks with BIM. As can be seen, all models perform significantly worse against this attack. Because the robustness is defined as the performance  under the worst case attack, this evaluation represents the real robustness of the models far better. We can see that the Basic Model and FGSM Model drop very fast with increased attack strength ε. So we can confirm that the FGSM Model overfits. Even though the Fast Newton Method and the random FGSM Model are also single-step adversarial training models, they perform significantly better under the attack with BIM than the FGSM Model. That shows that the idea of controlling the step sizes of adversarial attacks makes single-step adversarial training more effective. The outstanding performance of our Fast Newton Method compared to the FGSM models shows the importance of choosing the correct step size for creating adversarial examples during training. Additionally, our Fast Newton Method shows for small ε even better robustness than the more sophisticated BIM model, and is for larger ε equally robust while being significantly less computational expensive.

Results on VOC
Single-Step Robustness The robustness curves against the FGSM for models trained on PASCAL VOC are shown in fig. 4(a). We observe that the attack is not as effective on the Basic Model as on Cityscapes. We think that this is mainly reasoned in the characteristic of the dataset with its dominant background class. It seems difficult for the attack to switch the class of the whole background area. But as we already mentioned, the robustness is better represented by a strong multi-step attack. Our focus here lays again in the curve course of the FGSM Model. Like on Cityscapes the FGSM Model is most robust against the adversarial examples it was trained for (ε = 0 and ε = 0.03). So we see again an indicator for catastrophic overfitting.  Multi-Step Robustness Looking in Fig. 4(b) on the robustness of the trained models against the BIM, we can observe very similar results like on Cityscapes. Both, the Basic and the FGSM Model, perform much worse than the other models. So we can clearly say that the FGSM Model overfits to adversarial examples it was trained with. However, even if the random FGSM Model and the Fast Newton Method are trained with single-step adversarial examples, too, they perform significantly better than the FGSM Model. Thus, we can confirm that varying the step size increases the robustness of such models. Because the Fast Newton Method outperforms the random FGSM Model, we conclude that our proposed step size is more superior than determining the step size randomly. Additionally, even if our Fast Newton Method is less computational expensive than the BIM Model, their robustness is very similar.

Conclusion
The research community focused so far on improving the robustness of deep neural networks for image classification. We on the other hand concentrate on semantic segmentation. We showed that single-step adversarial training for semantic segmentation underlies the same difficulties regarding the robustness against multi-step adversarial attacks. One reason for that non-robustness of single step adversarial training is the static step size for finding the adversarial examples while training. Therefore, we presented a step size control algorithm which approximates an appropriate step size for every input such that the robustness of single-step adversarial training increases significantly. As our method approximates the best step size based on the gradient, which needs to be calculated anyway for adversarial training, our method does not considerably in-crease the computational effort while training a significantly more robust model. In addition, our approach is easy to use, because it is free of any parameter. Finally, we showed on the datasets, called Cityscapes and PASCAL VOC, that our method equals in performance with the more sophisticated and a lot more computationally expensive multi-step adversarial training.