0
0
PyTorchml~12 mins

Custom transforms in PyTorch - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Custom transforms

This pipeline shows how custom data transforms prepare images for a PyTorch model. The transforms clean and change images before training, helping the model learn better.

Data Flow - 4 Stages
1Raw Image Data
1000 images x 3 channels x 256 height x 256 widthOriginal images loaded from disk1000 images x 3 channels x 256 height x 256 width
An image of a cat with size 256x256 pixels and 3 color channels
2Custom Transform: Resize and Normalize
1000 images x 3 channels x 256 height x 256 widthResize images to 128x128 and normalize pixel values to 0-1 range1000 images x 3 channels x 128 height x 128 width
Resized cat image now 128x128 pixels with pixel values scaled between 0 and 1
3Custom Transform: Random Horizontal Flip
1000 images x 3 channels x 128 height x 128 widthRandomly flip images horizontally with 50% chance1000 images x 3 channels x 128 height x 128 width
Some cat images flipped left to right, others unchanged
4Tensor Conversion
1000 images x 3 channels x 128 height x 128 widthConvert images from numpy arrays to PyTorch tensors1000 tensors x 3 channels x 128 height x 128 width
Cat image now a PyTorch tensor ready for model input
Training Trace - Epoch by Epoch
Loss
1.2 |****
0.9 |***
0.7 |**
0.55|*
0.45| 
Epochs -> 1 2 3 4 5
EpochLoss ↓Accuracy ↑Observation
11.20.45Model starts learning with high loss and low accuracy
20.90.60Loss decreases and accuracy improves as model learns
30.70.72Model continues to improve with better predictions
40.550.80Loss lowers further, accuracy nearing good performance
50.450.85Model converges with low loss and high accuracy
Prediction Trace - 5 Layers
Layer 1: Input Image
Layer 2: Normalize Pixels
Layer 3: Random Horizontal Flip
Layer 4: Convert to Tensor
Layer 5: Model Forward Pass
Model Quiz - 3 Questions
Test your understanding
Why do we resize images in the custom transform?
ATo increase image size for better detail
BTo reduce image size and speed up training
CTo change image colors
DTo convert images to grayscale
Key Insight
Custom transforms prepare raw images by resizing, normalizing, and augmenting them. This helps the model learn better by giving consistent and varied data, leading to improved accuracy and faster training.