Sub topic 2
Invariance and Label-Preserving Transforms
Assume you know basic Python, image arrays, supervised learning, and the idea of overfitting. This chapter focuses on a key question: when does an augmented image still have the same correct answer?
What label preservation means
A transform changes an input image. A label-preserving transform changes the image without changing the target that the model must predict.
For example, suppose an image shows a cat and its classification label is cat. A small rotation usually keeps the label cat. The model should become invariant to that rotation, meaning its prediction should stay stable when the input changes in that way.
Augmentation is useful only when the modified example remains valid. If a transform changes the real answer, training on it can teach the model incorrect rules.
| Task | Possible label-preserving change | Risky change |
|---|---|---|
| Animal classification | Small crop or horizontal flip | Crop that removes the animal |
| Digit recognition | Small translation | Rotation that changes 6 into 9 |
| Traffic-sign classification | Mild brightness change | Horizontal flip of a directional sign |
| Tumor segmentation | Brightness change | Image transform without the same mask transform |
A transform can be safe for one dataset and unsafe for another. Label preservation depends on the task, the classes, and the expected image conditions.
Start with the task’s invariances
An invariance is a change that should not affect the target. Before selecting transforms, list changes that can occur in real inputs:
- Objects may appear at different positions or scales.
- A camera may be tilted slightly.
- Lighting and color temperature may vary.
- Parts of an object may be hidden.
- The image may contain sensor noise or blur.
Then ask whether each change leaves the label unchanged.
For ordinary object classification, a horizontal flip is often safe. For reading text, it is usually harmful because mirrored characters are different. A vertical flip is rarely safe for natural scenes because gravity and object orientation matter.
Geometric transforms
Geometric transforms change pixel locations. Common examples include:
- Translation, which moves the image.
- Scaling, which changes apparent size.
- Cropping, which removes part of the image.
- Rotation, which turns the image.
- Flipping, which mirrors the image.
Use small changes when the dataset contains small changes. A crop that removes background may be helpful, but a crop that removes the object can make the label ambiguous. Large rotations can produce views that never occur in deployment.
Geometric transforms also require correct interpolation. Image pixels can use bilinear interpolation, which creates smooth values. A class-index mask should usually use nearest-neighbor interpolation so class IDs are not blended.
Photometric transforms
Photometric transforms change appearance without moving objects. They include brightness, contrast, saturation, hue, noise, and blur.
These transforms often preserve labels for object identity. However, color may be part of the label. If the task distinguishes ripe from unripe fruit, strong color changes can destroy useful evidence. If a model will run on night images, brightness and contrast changes may improve generalization.
Occlusion transforms, such as cutout or random erasing, remove a region of the image. They encourage the model to use several object features instead of memorizing one small patch. Keep the erased area small enough that the object remains identifiable.
Check compositions, not only single transforms
Several mild transforms can combine into a severe change. A small crop followed by a rotation and erasing may remove the evidence needed for classification. Inspect complete augmented results, not just each operation separately.
For dense prediction tasks, such as segmentation and object detection, transform every paired target with the image. A flipped image needs a flipped mask. A resized image needs resized box coordinates. Photometric changes usually affect only the image because they do not change object location.
Exercise
Why can horizontal flipping be safe for animal classification but unsafe for text recognition?
Show answer
Animal identity usually stays the same after mirroring, while mirrored text changes character shapes and can change the correct label.