Skip to content
← Blog

Class-Dependent Data Augmentation · Part 1 of 2

One Augmentation, Opposite Effects: How Data Augmentation Helps Some Classes and Hurts Others

Solomon Owusu-Ansah · · 5 min read · Also on dev.to

Take one photo of a damaged bridge and turn up the contrast. It's one of the most routine augmentations in any training pipeline. In a study of class-dependent augmentation effects, that single edit improved detection for two of the damage types in the image and made it worse for six others.

Same image, same edit, opposite effects. The reason is that different classes are recognised by different visual cues, while augmentation is usually judged by one number averaged over all classes. An average can hide one class's loss behind another class's gain.

Different classes, different cues

A thin crack in concrete is recognised mostly by its shape and fine structure. Rust is recognised mostly by colour and texture. A hairline crack and a rust patch can sit side by side in the same image while depending on completely different visual information.

Standard pipelines apply one edit to the whole image. An edit that shifts colour threatens the classes that depend on colour. An edit that blurs fine texture threatens the hairline crack. So the same training image can gain information for one class and lose it for another.

This is easy to miss when you only look at the class-averaged score, because an average gain can sit on top of a per-class loss. Others have seen it too: augmentation that raised average accuracy on ImageNet lowered it for individual classes (Kirichenko et al.), and different augmentations for road damage affect each damage class differently (Tsuchiya et al.). The average isn't wrong. It's just answering a different question from the per-class one.

How the study measured it

The setup is simple in principle: train with one edit at a time and look at how AP50 changes for each class separately.

The study ran 258 training runs over three datasets and two detector families (Faster R-CNN and RetinaNet):

  • RDD2022: road damage, 4 classes
  • dacl10k: bridge damage, 12 classes
  • PASCAL VOC: 20 everyday object classes

For each dataset, detector and seed, a model was trained for three epochs on a base recipe (horizontal flip plus scale jitter). From that checkpoint, training continued for three more epochs in separate branches, one per edit, and each class's AP50 change was measured against a branch with no extra edit. The menu had 12 edits (13 on dacl10k): translation, rotation, brightness, contrast, saturation, hue, blur, noise, JPEG compression, sharpening, random erasing and mosaic.

The augmentation menu, applied to one real training image from each dataset — dacl10k (top), RDD2022 (middle), PASCAL VOC (bottom). Figure from the paper.

Every branch started from the same checkpoint with the same image order and the same random draws, so any two branches differ only in the edit. If a class gains in one branch and loses in another, it's reacting to the edit. Seed noise is still there, so the study tests for it statistically; the numbers are below.

The clearest case: contrast on bridge damage

On dacl10k with Faster R-CNN, raising the contrast helped Crack and Hollowareas in all three seeds. It hurt Efflorescence, Rust, Graffiti, Weathering, Restformwork and ExposedRebars, also in all three seeds. Two of the classes it hurt, rust and efflorescence, are the ones defined by colour.

One edit, two verdicts. The same dacl10k bridge image, unedited and with contrast raised — and the change in AP50 for each class. Hollowareas and Crack gain; Rust, Restformwork and four more classes lose. Figure from the paper.

Contrast isn't a one-off. Testing each edit separately with a Holm correction for multiple comparisons, contrast stayed significant (p = 0.002) and so did mosaic (p = 0.0003). Mosaic shows a different pattern. On PASCAL VOC with RetinaNet it helps on average (+1.82 AP50), but the per-class effect varies so much that class means span 7.6 AP50. Whether mosaic helps you depends heavily on which class you care about.

Every edit against every class

Here's the full grid: every edit against every class, on all three datasets and both detectors. Green is an AP50 gain, red a loss, and a dot means the change had the same sign in all three seeds.

Every edit against every class. Rows are edits, columns are classes; green is a gain in AP50, red is a loss, a dot means the change had the same sign in all three seeds. Panel titles give the statistical test for whether the effect depends on the class. Figure from the paper.

The formal test asks whether an edit's effect depends on the class beyond what the edit's average effect and the class's average sensitivity would explain.

With Faster R-CNN, it does on all three datasets: RDD2022 (p = 4.5 × 10⁻⁷), PASCAL VOC (p = 2.4 × 10⁻⁵) and dacl10k (p = 4.1 × 10⁻¹¹). With RetinaNet, only on PASCAL VOC (p < 10⁻⁶). On RDD2022 (p = 0.77) and dacl10k (p = 0.34), the RetinaNet differences between classes are about what seed noise alone would produce.

So in four of the six dataset–detector pairs, what an edit does to AP50 depends on which class you measure.

Caveats

The effects are small. Where class dependence shows up, the class-specific part of an effect is roughly 1–3 AP50 per cell over a three-epoch continuation, which is close to seed noise. That's why the conclusions rest on the interaction test and the corrected contrasts rather than on counting green and red cells. Most edits that flip sign across classes are within noise; only contrast and mosaic survive correction.

Short runs are a proxy. Effects were measured over three-epoch continuations. Checked against full 20-epoch training on one dataset and one detector, the agreement is moderate: rank correlation 0.56, with a wide interval (0.04 to 0.86). Trust the directions somewhat and treat the magnitudes as rough.

It doesn't hold for every detector. RetinaNet shows no class dependence on the two inspection datasets. The study doesn't test whether that's a real difference or whether its dense head needs more epochs before the differences show.

No edit wins everywhere. Averaged over classes, most edits cost a little in the short run, and none raises AP50 for every class in a dataset. Mosaic is the extreme: −3.55 AP50 on RDD2022 with Faster R-CNN, +1.82 on PASCAL VOC with RetinaNet.

What to do about it

If you judge an augmentation recipe by its average alone, you can end up with one that degrades the classes you care about most. Often those are the rare classes, which have the fewest examples to absorb the damage.

So look at per-class results whenever you test an augmentation. If one class drops while the average rises, you've made a trade-off, and you can't manage a trade-off you never measured.

The next post asks whether you can predict which classes an augmentation will hurt before spending any training compute.


Have you seen an augmentation, or any training trick, improve the average while hurting one class? Which class was it, and how did you notice?