0
0
PyTorchml~10 mins

Data augmentation 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 apply a random horizontal flip to an image tensor using PyTorch transforms.

PyTorch
transform = torchvision.transforms.Compose([torchvision.transforms.RandomHorizontalFlip(p=[1])])
Drag options to blanks, or click blank then click option'
A2
B1.5
C0.5
D-0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using a probability greater than 1 or less than 0.
Forgetting to set the probability parameter.
2fill in blank
medium

Complete the code to normalize an image tensor with mean 0.5 and std 0.5 using PyTorch transforms.

PyTorch
transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor(), torchvision.transforms.Normalize(mean=[[1]], std=[0.5])])
Drag options to blanks, or click blank then click option'
A0.0
B-0.5
C1.0
D0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean 0 or 1 which may not center the data properly.
Confusing mean and std values.
3fill in blank
hard

Fix the error in the code to apply random rotation of up to 30 degrees to an image tensor.

PyTorch
transform = torchvision.transforms.Compose([torchvision.transforms.RandomRotation(degrees=[1])])
Drag options to blanks, or click blank then click option'
A[30]
B(-30, 30)
C30
D30.0
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single integer instead of a range tuple.
Passing a list instead of a tuple.
4fill in blank
hard

Fill both blanks to create a transform that converts an image to tensor and then applies a random vertical flip with 30% chance.

PyTorch
transform = torchvision.transforms.Compose([[1](), torchvision.transforms.RandomVerticalFlip(p=[2])])
Drag options to blanks, or click blank then click option'
AToTensor
BRandomHorizontalFlip
C0.3
D0.7
Attempts:
3 left
💡 Hint
Common Mistakes
Using horizontal flip instead of vertical flip.
Setting probability to 0.7 instead of 0.3.
5fill in blank
hard

Fill all three blanks to create a transform pipeline that resizes images to 128x128, converts to tensor, and normalizes with mean 0.5 and std 0.5.

PyTorch
transform = torchvision.transforms.Compose([torchvision.transforms.[1]((128, 128)), torchvision.transforms.[2](), torchvision.transforms.Normalize(mean=[[3]], std=[0.5])])
Drag options to blanks, or click blank then click option'
AResize
BToTensor
C0.5
DCenterCrop
Attempts:
3 left
💡 Hint
Common Mistakes
Using CenterCrop instead of Resize.
Forgetting to convert images to tensors before normalization.