Computer Vision · Intermediate level

Intermediate level · Module 4: Data Augmentation · Lesson 2 of 3

Task-Aware Augmentation for Classification, Detection and Segmentation

Learners decide which augmentations are safe for each task (no colour changes when colour is the label, no flips for text) and augment bounding boxes and masks together with images.

In this lesson you will

  • Choose label-preserving augmentations for a task
  • Augment images with their boxes and masks

Key concepts

label-preserving transformscolour as signaltv_tensors.BoundingBoxestv_tensors.Masksynchronised transforms

The lesson

An augmentation is wrong if it changes the answer. Strong colour jitter can turn a ripe mango into an unripe-looking one; vertical flips make no sense for street scenes; flipping document images makes text unreadable. List the label-defining properties first, then choose transforms that leave them unchanged.

For detection and segmentation, geometric transforms must move boxes and masks with the image. torchvision.transforms.v2 does this when boxes are wrapped as tv_tensors.BoundingBoxes and masks as tv_tensors.Mask.

Visual checks are essential: draw the transformed boxes on the transformed images for a sample of examples before training.

Step by step

  1. List the label-defining properties of three tasks.
  2. Choose safe and unsafe augmentations for each.
  3. Augment an image with its bounding boxes using transforms.v2.
  4. Draw and check 10 augmented examples.

Practice activity

Write an augmentation policy for the level project's detection task and verify it visually.

Expected result: A justified policy and a gallery showing that boxes follow the objects correctly.

Check your understanding

  1. Why can colour jitter be harmful for ripeness classification?

    Show answer

    Colour is the signal that defines the label.

  2. What must happen to bounding boxes when an image is flipped?

    Show answer

    They must be flipped in the same way.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.