Robust and Accurate Object Detection via Adversarial Learning
- Publication
- CVPR 2021Conference
- First submitted to arXiv
- arXiv:2103.13886
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{objectdetectiondetadvprop2021,
title = {{Robust and Accurate Object Detection via Adversarial Learning}},
author = {Xiangning Chen and Cihang Xie and Mingxing Tan and Li Zhang and Cho-Jui Hsieh and Boqing Gong},
year = {2021},
eprint = {2103.13886},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/2103.13886}
}
Adversarial examples are usually used to attack models. Add a layer of noise the human eye can't see to an image, and a classifier takes a panda for a gibbon.
In 2019, Cihang Xie and colleagues at Google proposed AdvProp, which turns this around and uses adversarial examples as data augmentation for training EfficientNet. ImageNet accuracy went up rather than down, and the models also held up better against corruptions such as noise and blur.
This paper is the same group carrying AdvProp over to object detection. The first author, Xiangning Chen of UCLA, did the work during an internship at Google; the authors also include Cihang Xie and Mingxing Tan, an author of both EfficientNet and EfficientDet. The method is called Det-AdvProp.

The figure shows the three things this paper is after. Boxes on clean images should get more accurate, blurred and noisy images shouldn't throw the detector, and moving to another dataset shouldn't cost much either.
Problem Definition
Pretraining Gains Vanish After Fine-Tuning
The standard recipe for object detection is to pretrain a classification backbone on ImageNet and then fine-tune it on COCO. So the obvious idea is, since AdvProp and Noisy Student make classifiers stronger, why not just start the detector from the backbones they trained?
The authors tried it.

Red is the vanilla-pretrained backbone; orange and blue are the enhanced ones. After 300 epochs of fine-tuning, the three bars are almost the same height, and for D2 the enhanced ones are even slightly lower. With the B5 backbone, for example, the AdvProp version does gain 0.6% ImageNet accuracy on classification and has a 6.1% lower error rate under corruptions, yet on detection all of it is gone.
If pretraining won't carry the gains over, do the augmentation during fine-tuning instead.
The authors first tried AutoAugment, an augmentation policy searched specifically for detection, combining operations such as rotation and translating the pixels inside a box, with the search run on RetinaNet and a subset of COCO. On EfficientDet, though, its results were hit and miss, and D1 even lost 0.1. A policy searched on one detector doesn't necessarily carry over to another.
Adversarial examples don't have this problem. They are computed from the current model, so when the model changes, the augmentation changes with it, always aimed at wherever the model is weakest right now.
Solution
How AdvProp Works
First, a recap of AdvProp for classification. Its observation is that clean images and adversarial examples have different distributions; if they share the mean and variance of a single set of BatchNorm, the statistics get mixed together and neither side learns well.
So AdvProp prepares a separate set of auxiliary BatchNorm just for adversarial examples. At each training step, it first generates adversarial examples using the auxiliary BN, then sends clean images through the main BN and adversarial examples through the auxiliary BN, and backpropagates the sum of the two losses. Inference uses only the main BN; the auxiliary BN is simply thrown away.
A Detector Has Two Weak Spots
Moving to detection makes things harder. A one-stage detector's loss is the sum of a classification term and a localization term:
is the classification loss (focal loss, for example) and the box regression loss (Huber loss, for example). To generate adversarial examples, you can attack classification or attack localization, so there are two weak spots to hit.
The most direct approach is to attack the total loss . The authors found that this doesn't work well, about the same as attacking classification alone, or even worse. The reason is that the gradients of the two losses with respect to the input, and , have different value ranges and often point in different directions; added together they cancel each other out, and the resulting adversarial examples end up weaker.
Another approach is to generate both kinds of attack and give each its own auxiliary BN, three sets of BN in total. This version is the most robust to corruptions, but accuracy on clean images drops. The authors suspect that two auxiliary BNs regularize too strongly, so the model underfits the clean training data.
Pick the Stronger of the Two
Det-AdvProp takes the best of both. For each image, it uses FGSM to attack classification and localization separately, producing one adversarial example from each:
FGSM simply adds or subtracts at each pixel according to the sign of the loss gradient, in a single step; projects the result back to within of the original image.
Then it keeps only the one that makes the total loss larger:
This "max-max" rule comes from Zhang et al.'s work on adversarial training for detectors. The inner max attacks each branch on its own; the outer max picks the nastier of the two candidates. Because the two gradients are computed separately, they can't cancel each other out; and with only one adversarial example per image and one set of auxiliary BN, there is no over-regularization either.
The training objective is simply the sum of the losses on the clean image and the adversarial example:
After training, the auxiliary BN is discarded, and the model has exactly the same parameter count and inference latency as one trained the ordinary way.
Some Implementation Details
The attack strength goes up to only 3/255, much smaller than the 8/255 common in adversarial training; the default is 1/255. Input images are first scaled to [−1, 1] to make the perturbation easier to compute.
There are also two kinds of attack. A targeted attack swaps the labels for random wrong classes and then pushes the model toward that wrong answer; a non-targeted attack just makes the original loss larger. Choosing by clean accuracy, the authors use targeted attacks for D0 to D2 and non-targeted attacks for D3 to D5.
The targeted attack has one more detail. A detector has a huge number of anchors, most of them on the background. The authors tried perturbing the labels of only the anchors covering objects, and the result was about the same as no augmentation; only when every anchor, background included, got a random label did it help. Their explanation is that background features matter too, and there are too few anchors covering objects.
The detectors are EfficientDet D0 to D5, trained on COCO for 300 epochs; the original data augmentation is just horizontal flipping and scale jittering.
Discussion
COCO
| Model | Vanilla | + AutoAugment | + Det-AdvProp |
|---|---|---|---|
| EfficientDet-D0 | 34.3 | 34.4 | 34.7 |
| EfficientDet-D1 | 40.2 | 40.1 | 40.5 |
| EfficientDet-D2 | 43.5 | 43.5 | 43.8 |
| EfficientDet-D3 | 46.8 | 47.0 | 47.6 |
| EfficientDet-D4 | 49.3 | 49.5 | 49.8 |
| EfficientDet-D5 | 51.3 | 51.5 | 51.8 |
Compiled from Table 1 of the paper, COCO val2017 mAP.
Det-AdvProp improves at every size, though not by much. The small models D0 to D2 gain only 0.3 to 0.4, and the large models D3 to D5 gain 0.5 to 0.8. The authors say the improvement comes mainly from large and medium objects; looking closely at the table, small-object AP actually drops by 0.6 on D1 and D4.
The two augmentations also stack. With Det-AdvProp plus AutoAugment, every model from D3 up gains at least 1.0 mAP; D4 reaches 50.4 mAP with just 21 million parameters, close to the 50.7 of AmoebaNet plus NAS-FPN plus AutoAugment, which has 209 million.
The effect is larger when training from scratch without ImageNet pretraining. D3 goes from 41.7 to 43.8, a gain of 2.1.
Single Categories
Some applications detect only one kind of thing. The authors picked three categories from COCO and trained a separate single-category D3 for each:
| Class | Size | Images | Vanilla | + AutoAugment | + Det-AdvProp |
|---|---|---|---|---|---|
| Donut | Small | 1,585 | 25.4 | 23.9 | 28.7 |
| Person | Medium | 66,808 | 58.2 | 58.0 | 58.5 |
| Truck | Large | 6,377 | 28.1 | 25.5 | 28.7 |
Compiled from Table 3 of the paper, EfficientDet-D3.
AutoAugment's policy was searched for 80 categories; on single categories all three get worse, with truck dropping 2.6. Det-AdvProp improves all three; donut, with the least training data, gains 3.3, while person, with more than 60,000 images, gains only 0.3. The less data there is, the more the model learns from its own weak spots.
Corruptions and Other Datasets
Robustness is where this method really pulls ahead. COCO-C is the COCO validation set with 15 common corruptions added, such as noise, blur, weather and compression, each at 5 severity levels. EfficientDet-D4 rises from 30.1 to 32.8 on COCO-C, a gain of 2.7, five times its gain on clean images (0.5); under the same conditions, AutoAugment gains only 1.4.

This heat map breaks the gain down by corruption and by severity. The top few rows are noise types, with Gaussian noise gaining 4.36 on average and shot noise 4.08, while brightness at the bottom gains only 1.22. Reading from left to right, the stronger the corruption, the redder the cells.
It's no surprise that noise gains the most. The perturbation FGSM produces is itself fine noise added to every pixel; a model that has trained on it is naturally steadier when it meets random noise.
Across datasets, taking models trained on COCO and testing them directly on PASCAL VOC 2012, Det-AdvProp is better at every size, with D5 gaining 0.8. AutoAugment, on the other hand, drops D2 by 0.6.
Ablations
Both maxes are needed.
| Variant | COCO | COCO-C | rPC |
|---|---|---|---|
| Vanilla | 46.8 | 28.8 | 61.5 |
| Attack loc. only | 47.1 | 30.0 | 63.7 |
| Attack cls. only | 47.2 | 30.5 | 64.6 |
| Attack total loss | 47.1 | 30.4 | 64.5 |
| Three BNs | 46.7 | 30.6 | 65.5 |
| Det-AdvProp | 47.6 | 30.8 | 64.7 |
Compiled from Table 8 of the paper, EfficientDet-D3. rPC is COCO-C mAP divided by clean mAP, as a percentage.
When attacking a single branch, hitting classification works better than hitting localization, from which the authors infer that the drop caused by corruptions happens mainly in the classification branch. Attacking the total loss lands between the two, consistent with the idea that the gradients cancel each other out. Three BNs give the highest rPC, but their clean-image mAP is even lower than vanilla training. Det-AdvProp has the highest mAP on both COCO and COCO-C.
Attack strength depends on model size. The small models D0 to D2 do best at and start to suffer beyond that; the large models D3 to D5 do best at , where D5 gains another 0.2. The same goes for non-targeted attacks, which bring more robustness to large models but lower clean accuracy in small ones. The larger a model's capacity, the stronger the augmentation it can take.
Against conventional adversarial training. Standard adversarial training with the same drops D1 on COCO from 40.2 to 38.0. Adversarial training aims to resist attacks and usually sacrifices clean accuracy; Det-AdvProp's auxiliary BN keeps the two distributions apart, which is how it manages both.
The Cost
Every step needs an extra forward and backward pass to generate the adversarial example, which makes training roughly three times as expensive. The authors also tested spending the same budget on stretching vanilla training to 900 epochs. D1 and D3 rose only from 40.2 and 46.8 to 40.3 and 47.0, with no change at all on COCO-C and VOC, whereas Det-AdvProp reaches 40.5 and 47.6. The extra compute does more good spent on adversarial examples than on longer training.
Inference costs nothing extra.
Conclusion
0.3 to 0.8 more mAP on COCO doesn't look like much; the weight of this paper is on COCO-C. For the same D4, it gains 2.7 mAP under noise, blur and compression, and AutoAugment manages only half that. The detector finds its own weak spots and patches wherever it finds them, and a new model doesn't need a new policy search.
If image quality in your deployment is unstable, as with the noisy, compressed footage from surveillance cameras and dashcams, this is an option that costs three times the training time and nothing at inference. The official EfficientDet repository has Det-AdvProp weights for D0 to D5 (trained together with AutoAugment) ready to use; remember to scale inputs to [−1, 1], which differs from the original EfficientDet normalization.
Just don't treat it as a tool for defending against adversarial attacks. The paper measures clean images, natural corruptions and cross-dataset transfer, and never once turns an adversarial attack on the trained models.