When using data augmentation in computer vision, the key metric to watch is generalization performance, often measured by validation accuracy or validation loss. Augmentation creates new, varied images from existing ones, helping the model learn to recognize objects under different conditions. This reduces overfitting and improves how well the model works on new, unseen images. So, metrics that show how well the model performs on data it has never seen before are the most important.
Why augmentation multiplies training data in Computer Vision - Why Metrics Matter
Confusion Matrix Example (Augmented Data Model):
Predicted
Cat Dog
Actual Cat 45 5
Dog 4 46
Total samples: 100
- True Positives (TP): 45 (correctly predicted Cat)
- True Negatives (TN): 46 (correctly predicted Dog)
- False Positives (FP): 4 (Dog predicted as Cat)
- False Negatives (FN): 5 (Cat predicted as Dog)
Precision = TP / (TP + FP) = 45 / (45 + 4) = 0.918
Recall = TP / (TP + FN) = 45 / (45 + 5) = 0.9
F1 Score = 2 * (Precision * Recall) / (Precision + Recall) ≈ 0.909Imagine a model trained with and without augmentation:
- Without augmentation: The model sees fewer variations, so it might memorize training images but fail on new ones. This can cause high precision but low recall because it only confidently predicts what it has seen.
- With augmentation: The model learns to recognize objects in many forms (rotated, brightened, flipped). This usually improves recall because it finds more true positives, even if precision slightly drops due to more challenging cases.
For example, in a dog vs cat classifier, augmentation helps the model spot a dog even if the photo is blurry or rotated, increasing recall.
Good metrics:
- Validation accuracy above 85% on varied images
- Balanced precision and recall around 90%
- F1 score close to precision and recall, showing consistent performance
Bad metrics:
- High training accuracy but low validation accuracy (overfitting)
- Very high precision but very low recall (model misses many true cases)
- Validation accuracy below 70%, showing poor generalization
- Accuracy paradox: High accuracy can be misleading if classes are imbalanced. For example, if 90% of images are cats, predicting all cats yields 90% accuracy but no real learning.
- Data leakage: Augmented images too similar to training images in validation can inflate metrics falsely.
- Overfitting indicators: Large gap between training and validation accuracy means the model memorizes training data but fails to generalize.
Your model trained with augmentation has 98% training accuracy but only 12% recall on the dog class in validation. Is it good for production? Why or why not?
Answer: No, it is not good. The very low recall means the model misses most dogs, which is critical if detecting dogs is important. Despite high training accuracy, the model fails to generalize and recognize dogs in new images. This suggests overfitting or ineffective augmentation.
Practice
Solution
Step 1: Understand augmentation purpose
Augmentation creates new images by applying changes like rotation or flipping to existing images.Step 2: Connect augmentation to data size
These new images increase the total number of training samples, effectively multiplying the dataset size.Final Answer:
Because it creates new images by changing existing ones -> Option AQuick Check:
Augmentation = new image versions [OK]
- Thinking augmentation deletes images
- Confusing augmentation with compression
- Believing augmentation automatically labels data
Solution
Step 1: Recall torchvision syntax
In torchvision, horizontal flip is done with RandomHorizontalFlip and a probability parameter.Step 2: Check options for correct class and parameters
Only transform = transforms.RandomHorizontalFlip(p=1.0) uses the correct class name and parameter format.Final Answer:
transform = transforms.RandomHorizontalFlip(p=1.0) -> Option CQuick Check:
Correct torchvision flip syntax = transform = transforms.RandomHorizontalFlip(p=1.0) [OK]
- Using incorrect class names like HorizontalFlip
- Missing the probability parameter p
- Assuming FlipHorizontal exists in torchvision
Solution
Step 1: Calculate augmented images per original
Each original image produces 3 new augmented images plus the original itself, totaling 4 images per original.Step 2: Multiply by original dataset size
100 original images * 4 images each = 400 images total after augmentation.Final Answer:
400 -> Option BQuick Check:
(3 augmentations + 1 original) * 100 = 400 [OK]
- Counting only augmented images, ignoring originals
- Multiplying by 3 instead of 4
- Adding instead of multiplying
from torchvision import transforms
transform = transforms.Compose([
transforms.RandomRotation(30),
transforms.RandomFlip(horizontal=true)
])Solution
Step 1: Check torchvision augmentation classes
There is no RandomFlip class in torchvision; horizontal flip uses RandomHorizontalFlip.Step 2: Identify correct fix
Replacing RandomFlip with RandomHorizontalFlip fixes the error; other options are incorrect or unnecessary.Final Answer:
Replace RandomFlip with RandomHorizontalFlip -> Option AQuick Check:
Correct flip class = RandomHorizontalFlip [OK]
- Assuming RandomFlip exists
- Changing rotation syntax unnecessarily
- Adding parameters to non-existent classes
Solution
Step 1: Understand multiplication goal
To multiply data by 5 times, total images after augmentation should be 50 * 5 = 250.Step 2: Calculate images per original
Keeping original plus 4 augmentations per image gives 5 images per original, totaling 250 images.Step 3: Evaluate options
Apply 4 different augmentations per image plus keep original images achieves the goal without losing original images; others either discard originals or don't reach 5x.Final Answer:
Apply 4 different augmentations per image plus keep original images -> Option DQuick Check:
Original + 4 augmentations = 5x data [OK]
- Discarding original images reduces data size
- Duplicating images without augmentation doesn't add variety
- Training longer without augmentation doesn't multiply data
Ready to prove it?
Pass the test and this pattern moves unknown
