Challenge - 5 Problems
Data Augmentation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a composed transform on an image tensor
Given the following PyTorch code applying data augmentation transforms, what is the shape of the output tensor after the transforms?
PyTorch
import torch from torchvision import transforms from PIL import Image transform = transforms.Compose([ transforms.Resize((64, 64)), transforms.RandomHorizontalFlip(p=1.0), transforms.ToTensor() ]) # Simulate a PIL image as a tensor with shape (3, 100, 100) # Normally transforms expect PIL images, so convert tensor to PIL Image image = Image.fromarray((torch.rand(3, 100, 100).permute(1, 2, 0).mul(255).byte().numpy())) output = transform(image) print(output.shape)
Attempts:
2 left
💡 Hint
Remember that Resize changes the image size and ToTensor converts to a tensor with channels first.
✗ Incorrect
The Resize transform changes the image size to 64x64 pixels. The RandomHorizontalFlip flips the image horizontally but does not change shape. ToTensor converts the image to a tensor with shape (channels, height, width). So the output shape is (3, 64, 64).
❓ Model Choice
intermediate1:30remaining
Choosing the best augmentation for rotation invariance
You want to train a model to recognize objects regardless of their orientation. Which data augmentation transform should you add to your training pipeline to help the model learn rotation invariance?
Attempts:
2 left
💡 Hint
Think about which transform changes the orientation of the image.
✗ Incorrect
RandomRotation rotates the image by a random angle up to 45 degrees, helping the model learn to recognize objects in different orientations. HorizontalFlip flips the image but only horizontally, ColorJitter changes colors, and RandomCrop changes the size and position but not orientation.
❓ Hyperparameter
advanced1:00remaining
Effect of probability parameter in RandomHorizontalFlip
In the transform transforms.RandomHorizontalFlip(p=0.7), what does the parameter p=0.7 control?
Attempts:
2 left
💡 Hint
Think about what 'p' usually means in random transforms.
✗ Incorrect
The parameter p in RandomHorizontalFlip sets the chance that the image will be flipped horizontally. Here, there is a 70% chance the image flips and 30% chance it stays the same.
🔧 Debug
advanced2:00remaining
Debugging a transform pipeline error
You have this transform pipeline:
transform = transforms.Compose([
transforms.ToTensor(),
transforms.RandomCrop(32),
transforms.Normalize(mean=[0.5], std=[0.5])
])
When you run it on a PIL image of size 28x28, you get an error. What is the cause?
Attempts:
2 left
💡 Hint
Check the image size compared to the crop size.
✗ Incorrect
RandomCrop(32) tries to crop a 32x32 patch, but the input image is only 28x28, so it raises an error. To fix, either resize the image first or use a smaller crop size.
🧠 Conceptual
expert1:30remaining
Why use data augmentation in training deep learning models?
Which of the following best explains why data augmentation is important when training deep learning models?
Attempts:
2 left
💡 Hint
Think about how data augmentation affects the training data and model learning.
✗ Incorrect
Data augmentation creates new variations of existing data, helping the model learn more robust features and reducing overfitting. It does not reduce training time or guarantee perfect accuracy.