A. transforms.Rotate doesn't exist; should use transforms.functional.rotate or transforms.RandomRotation
B. The angle 45 must be in radians, not degrees
C. ToTensor must come before Rotate
D. Image.open returns a tensor, so transform fails
Solution
Step 1: Check torchvision transform names
There is no transforms.Rotate class. Rotation is done with transforms.RandomRotation or using functional API.
Step 2: Identify correct usage
To rotate by a fixed angle, use transforms.RandomRotation([45, 45]) or transforms.functional.rotate. The code as is will cause an AttributeError.
Final Answer:
transforms.Rotate doesn't exist; should use transforms.functional.rotate or transforms.RandomRotation -> Option A
Quick Check:
No transforms.Rotate in torchvision [OK]
Hint: Check transform names carefully; Rotate is not a direct class [OK]
Common Mistakes:
Using non-existent transform classes
Confusing degrees and radians
Wrong order of transforms
5. You want to augment a dataset of images to improve model robustness. Which combination of transforms would best simulate real-world variations while keeping image size constant?
hard
A. transforms.RandomCrop(224), transforms.RandomRotation(180), transforms.Resize(128)
B. transforms.Resize(256), transforms.CenterCrop(224), transforms.RandomVerticalFlip() only
C. transforms.RandomRotation(90), transforms.RandomCrop(200), transforms.ToTensor()
D. transforms.RandomResizedCrop(224), transforms.RandomHorizontalFlip(), transforms.ColorJitter(brightness=0.2, contrast=0.2)
Solution
Step 1: Understand augmentation goals
We want to simulate real-world changes like size, flip, and color while keeping output size fixed.
Step 2: Evaluate options
transforms.RandomResizedCrop(224), transforms.RandomHorizontalFlip(), transforms.ColorJitter(brightness=0.2, contrast=0.2) resizes and crops randomly to 224x224, flips horizontally, and changes brightness/contrast, all common augmentations that keep size constant.
Step 3: Check other options
transforms.Resize(256), transforms.CenterCrop(224), transforms.RandomVerticalFlip() only flips vertically and crops but lacks color changes. transforms.RandomRotation(90), transforms.RandomCrop(200), transforms.ToTensor() changes size unpredictably and transforms.RandomCrop(224), transforms.RandomRotation(180), transforms.Resize(128) resizes after cropping, changing size.
Final Answer:
transforms.RandomResizedCrop(224), transforms.RandomHorizontalFlip(), transforms.ColorJitter(brightness=0.2, contrast=0.2) -> Option D
Quick Check:
Best augmentations keep size fixed and add variety [OK]
Hint: Pick transforms that keep size fixed and add flip + color changes [OK]
Common Mistakes:
Choosing transforms that change image size unpredictably