0
0
PyTorchml~10 mins

Data augmentation with transforms in PyTorch - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the torchvision transforms module.

PyTorch
from torchvision import [1]
Drag options to blanks, or click blank then click option'
Autils
Btransforms
Cdatasets
Dmodels
Attempts:
3 left
💡 Hint
Common Mistakes
Importing datasets instead of transforms
Importing models which is unrelated to data augmentation
2fill in blank
medium

Complete the code to create a transform that randomly flips images horizontally.

PyTorch
transform = transforms.[1](p=0.5)
Drag options to blanks, or click blank then click option'
AColorJitter
BRandomRotation
CRandomHorizontalFlip
DRandomCrop
Attempts:
3 left
💡 Hint
Common Mistakes
Using RandomRotation which rotates images instead of flipping
Using ColorJitter which changes colors, not flips
3fill in blank
hard

Fix the error in the transform pipeline to convert images to tensor after resizing.

PyTorch
transform = transforms.Compose([
    transforms.Resize((128, 128)),
    transforms.[1](),
])
Drag options to blanks, or click blank then click option'
AToTensor
BToPILImage
CNormalize
DRandomCrop
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToPILImage which converts tensor back to image
Using Normalize without converting to tensor first
4fill in blank
hard

Fill both blanks to create a transform pipeline that randomly crops and then normalizes images.

PyTorch
transform = transforms.Compose([
    transforms.[1](size=100),
    transforms.ToTensor(),
    transforms.[2](mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
])
Drag options to blanks, or click blank then click option'
ARandomCrop
BRandomHorizontalFlip
CNormalize
DResize
Attempts:
3 left
💡 Hint
Common Mistakes
Using Resize instead of RandomCrop for cropping
Using RandomHorizontalFlip instead of Normalize for normalization
5fill in blank
hard

Fill all three blanks to create a transform pipeline that resizes, converts to tensor, and applies random rotation.

PyTorch
transform = transforms.Compose([
    transforms.[1]((64, 64)),
    transforms.[2](),
    transforms.[3](degrees=30)
])
Drag options to blanks, or click blank then click option'
AResize
BToTensor
CRandomRotation
DCenterCrop
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing order of transforms causing errors
Using CenterCrop instead of Resize for resizing