0
0
PyTorchml~5 mins

Data transforms in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a data transform in PyTorch?
A data transform is a function or operation applied to data samples to change or prepare them before feeding into a model. It can include resizing images, normalizing values, or converting data types.
Click to reveal answer
beginner
Why do we normalize images in data transforms?
Normalization scales image pixel values to a standard range, often zero mean and unit variance. This helps the model learn better and faster by keeping input values consistent.
Click to reveal answer
intermediate
How does the Compose transform work in PyTorch?
Compose chains multiple transforms together. It applies each transform in order to the data sample, making it easy to combine steps like resizing, cropping, and normalizing.
Click to reveal answer
beginner
What is the purpose of ToTensor transform?
ToTensor converts images or data from PIL Image or numpy arrays into PyTorch tensors. It also scales pixel values from 0-255 integers to 0-1 floats.
Click to reveal answer
intermediate
Give an example of a common data transform pipeline for image classification.
A typical pipeline: Resize image to fixed size, convert to tensor, normalize with mean and std. For example: Compose([Resize(256), CenterCrop(224), ToTensor(), Normalize(mean, std)]).
Click to reveal answer
What does the Normalize transform do in PyTorch?
ARandomly flips images horizontally
BConverts images to tensors
CResizes images to a fixed size
DScales data to zero mean and unit variance
Which transform converts a PIL image to a PyTorch tensor?
AResize
BToTensor
CNormalize
DRandomCrop
What is the main use of Compose in data transforms?
ATo chain multiple transforms together
BTo normalize images
CTo convert data to tensors
DTo load datasets
Why do we resize images in data transforms?
ATo make all images the same size for the model
BTo convert images to grayscale
CTo increase image brightness
DTo shuffle image pixels
Which transform would you use to randomly flip images horizontally?
ACenterCrop
BNormalize
CRandomHorizontalFlip
DToTensor
Explain the role of data transforms in preparing images for a PyTorch model.
Think about steps to make images ready and consistent for training.
You got /4 concepts.
    Describe how you would create a data transform pipeline for training an image classifier.
    Consider both preparing and augmenting images.
    You got /4 concepts.