0
0
PyTorchml~10 mins

Compose 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 create a composed transform that converts images to tensors.

PyTorch
transform = transforms.Compose([transforms.To[1]()])
Drag options to blanks, or click blank then click option'
ATensor
BImage
CPIL
DArray
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToImage instead of ToTensor.
Using ToPIL which converts tensors back to images.
2fill in blank
medium

Complete the code to normalize images with mean 0.5 and std 0.5 using Compose.

PyTorch
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize(mean=[[1]], std=[0.5])])
Drag options to blanks, or click blank then click option'
A0.0
B1.0
C0.5
D0.25
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean 0.0 which does not center the data properly.
Using std 1.0 which does not scale the data.
3fill in blank
hard

Fix the error in the Compose transform that should resize images to 128x128 pixels.

PyTorch
transform = transforms.Compose([transforms.Resize([1])])
Drag options to blanks, or click blank then click option'
A128
B(128, 128)
C[128, 128]
D128, 128
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a single integer which resizes the smaller edge only.
Using a list instead of a tuple.
4fill in blank
hard

Fill both blanks to create a Compose transform that converts images to tensors and then randomly flips them horizontally.

PyTorch
transform = transforms.Compose([transforms.[1](), transforms.[2](p=0.5)])
Drag options to blanks, or click blank then click option'
AToTensor
BRandomCrop
CRandomHorizontalFlip
DNormalize
Attempts:
3 left
💡 Hint
Common Mistakes
Using RandomCrop instead of RandomHorizontalFlip.
Normalizing before converting to tensor.
5fill in blank
hard

Fill all three blanks to create a Compose transform that resizes images to 64x64, converts to tensor, and normalizes with mean 0.5 and std 0.5.

PyTorch
transform = transforms.Compose([transforms.Resize([1]), transforms.[2](), transforms.Normalize(mean=[[3]], std=[0.5])])
Drag options to blanks, or click blank then click option'
A(64, 64)
BToTensor
C0.5
DRandomVerticalFlip
Attempts:
3 left
💡 Hint
Common Mistakes
Using RandomVerticalFlip instead of ToTensor.
Passing size as a list instead of a tuple.