Data augmentation for object detection

Augmentation shows the model the same objects in new ways, so it learns the object rather than the photo.

5 min read

Why it works

A model trained on a few hundred photos can memorise them: this exact background, this exact light. Augmentation changes each image a little every time the model sees it, so the only thing that stays the same is the object.

Transforms that help detectors

  • Horizontal flip: almost always safe. Not for text, or for left and right that matter.
  • Scale and crop: teaches the model objects at many sizes and partly cut off.
  • Colour, brightness and contrast: covers changes in light and cameras.
  • Mosaic: four images tiled into one, so each training image holds more objects and more context. Most useful early in training; it is usually switched off for the last epochs so the model finishes on natural images.

Transforms that can hurt

  • Vertical flips, when the world has an up and a down.
  • Heavy blur or noise beyond what your camera produces.
  • Rotations, unless the boxes are rebuilt carefully: a rotated box no longer fits its object.

Boxes move with the image

Every geometric transform must apply to the labels too. A flipped image with unflipped boxes is worse than no augmentation. fotonet's training pipeline handles this for its own transforms; check it when you add your own.

See it before you train

Look at a few augmented images, boxes drawn, before a long run. fotonet Studio's Augment tab shows each image next to its augmented copy for exactly this reason. See fotonet Studio.