0
0
PyTorchml~5 mins

Compose transforms in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of Compose in PyTorch transforms?

Compose lets you combine multiple image transformations into one sequence. It applies each transform one after another to the input data.

Click to reveal answer
beginner
How do you use Compose to apply a resize and then convert an image to a tensor?
transform = Compose([Resize((128, 128)), ToTensor()])

This creates a transform that first resizes images to 128x128 pixels, then converts them to tensors.

Click to reveal answer
intermediate
What happens if you change the order of transforms inside Compose?

The transforms are applied in the order you list them. Changing order can change the final output. For example, Normalize() before ToTensor() will cause an error.

Click to reveal answer
intermediate
Can Compose include custom transforms?
<p>Yes! You can write your own transform as a class or function and include it inside <code>Compose</code> along with built-in transforms.</p>
Click to reveal answer
beginner
What is the output of applying Compose([Resize((64,64)), ToTensor()]) to an image?

The output is a PyTorch tensor representing the image resized to 64x64 pixels, ready for model input.

Click to reveal answer
What does Compose do in PyTorch transforms?
ALoads images from disk
BCreates a new dataset
CTrains a neural network
DChains multiple transforms to apply in sequence
Which of these is a correct way to use Compose?
ACompose([Resize((128,128)), ToTensor()])
BCompose([ToTensor(), Resize((128,128))])
CCompose(Resize((128,128)), ToTensor())
DCompose(ToTensor())
What type of object does ToTensor() produce?
ANumPy array
BPyTorch tensor
CPython list
DPIL Image
If you want to add a custom transform to Compose, what must it do?
ATrain a model
BLoad data from disk
CReturn a transformed image or tensor
DPrint the image
What happens if you put Normalize() before ToTensor() in Compose?
ANormalize will fail because input is a PIL image, not a tensor
BIt works fine
CThe image will be normalized twice
DThe image will convert back to tensor
Explain how Compose helps when preparing images for a PyTorch model.
Think about how you get images ready step-by-step.
You got /4 concepts.
    Describe what could go wrong if you change the order of transforms inside Compose.
    Consider what happens if you convert to tensor too early.
    You got /4 concepts.