Challenge - 5 Problems
Data Transform Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output shape after applying this transform?
Consider a PyTorch tensor representing an image of shape (3, 64, 64). We apply the following transform:
What will be the shape of the resulting tensor after applying
transform = torchvision.transforms.Compose([torchvision.transforms.Resize(32), torchvision.transforms.CenterCrop(28)])What will be the shape of the resulting tensor after applying
transform?PyTorch
import torch import torchvision.transforms as T img = torch.randn(3, 64, 64) transform = T.Compose([T.Resize(32), T.CenterCrop(28)]) result = transform(img) print(result.shape)
Attempts:
2 left
💡 Hint
Resize changes the smaller edge to 32, then CenterCrop cuts a 28x28 square from the center.
✗ Incorrect
Resize changes the image so the smaller edge is 32, keeping aspect ratio. Since input is square 64x64, it becomes 32x32. Then CenterCrop crops a 28x28 patch from the center. The channel dimension (3) stays the same.
❓ Model Choice
intermediate2:00remaining
Which transform is best to normalize image pixels to [0,1] range?
You have image tensors with pixel values from 0 to 255. You want to normalize them to the range [0,1] before feeding into a model. Which PyTorch transform should you use?
Attempts:
2 left
💡 Hint
One transform converts PIL images or numpy arrays to tensors and scales pixels to [0,1].
✗ Incorrect
ToTensor() converts images to float tensors and scales pixel values from [0,255] to [0,1]. Normalize changes mean and std but does not scale 0-255 to 0-1.
❓ Hyperparameter
advanced2:00remaining
Choosing mean and std for Normalize transform
You want to normalize RGB images using torchvision.transforms.Normalize. Which values for mean and std are correct if your images have pixel values in [0,1] and you want zero mean and unit variance per channel?
Attempts:
2 left
💡 Hint
Zero mean and unit variance means subtract 0 and divide by 1.
✗ Incorrect
Normalize subtracts mean and divides by std. To keep zero mean and unit variance, use mean=0 and std=1 for each channel.
🔧 Debug
advanced2:00remaining
Why does this transform code raise an error?
This code raises an error when applied to a tensor image. Why?
Assume input is a PyTorch tensor image.
transform = torchvision.transforms.Compose([torchvision.transforms.RandomHorizontalFlip(), torchvision.transforms.ToTensor()])Assume input is a PyTorch tensor image.
PyTorch
import torch import torchvision.transforms as T img = torch.randn(3, 64, 64) transform = T.Compose([T.RandomHorizontalFlip(), T.ToTensor()]) result = transform(img)
Attempts:
2 left
💡 Hint
Check the expected input types for RandomHorizontalFlip.
✗ Incorrect
RandomHorizontalFlip works on PIL images or numpy arrays, not on PyTorch tensors. Applying it directly to a tensor causes an error.
🧠 Conceptual
expert2:00remaining
Why use data transforms during training but not always during testing?
In machine learning, why do we often apply random data transforms (like flips, crops) during training but use fixed transforms during testing?
Attempts:
2 left
💡 Hint
Think about how randomness affects learning and evaluation.
✗ Incorrect
Random transforms create varied training examples to help the model learn robust features. During testing, fixed transforms ensure the evaluation is stable and reproducible.