0
0
PyTorchml~12 mins

Built-in datasets (torchvision.datasets) in PyTorch - Model Pipeline Trace

Choose your learning style9 modes available
Model Pipeline - Built-in datasets (torchvision.datasets)

This pipeline shows how to use a built-in dataset from torchvision.datasets to train a simple image classifier. It loads data, processes images, trains a model, and evaluates accuracy.

Data Flow - 5 Stages
1Load Dataset
N/ADownload and load CIFAR10 dataset with 60000 images of size 32x32x360000 images x 32 x 32 x 3
Image of a small airplane with RGB channels
2Preprocessing
60000 images x 32 x 32 x 3Convert images to tensors and normalize pixel values to mean=0.5, std=0.560000 images x 3 x 32 x 32 (tensor format)
Tensor with values roughly between -1 and 1
3Train/Test Split
60000 images x 3 x 32 x 32Split into 50000 training and 10000 test imagesTrain: 50000 x 3 x 32 x 32, Test: 10000 x 3 x 32 x 32
Training batch of 64 images
4Model Training
Batch of 64 images x 3 x 32 x 32Train a simple CNN classifier for 5 epochsModel weights updated, loss decreases
Batch loss starts around 2.0 and decreases
5Evaluation
Test set 10000 images x 3 x 32 x 32Model predicts labels, compute accuracyAccuracy score between 0 and 1
Final accuracy around 0.65 (65%)
Training Trace - Epoch by Epoch
Loss
2.0 |****
1.8 |****
1.6 |*** 
1.4 |*** 
1.2 |**  
1.0 |**  
0.8 |*   
    +------------
     1 2 3 4 5 Epochs
EpochLoss ↓Accuracy ↑Observation
11.850.35Model starts learning, loss high, accuracy low
21.450.48Loss decreases, accuracy improves
31.200.57Model continues to learn patterns
41.050.62Loss steadily decreases, accuracy rises
50.950.65Training converges with good accuracy
Prediction Trace - 5 Layers
Layer 1: Input Image Tensor
Layer 2: Convolutional Layer 1
Layer 3: Max Pooling Layer
Layer 4: Fully Connected Layer
Layer 5: Softmax Activation
Model Quiz - 3 Questions
Test your understanding
What is the shape of the dataset images after loading from torchvision.datasets?
A50000 images x 3 x 32 x 32
B60000 images x 32 x 32 x 3
C60000 images x 3 x 32 x 32
D10000 images x 32 x 32 x 3
Key Insight
Using torchvision.datasets makes it easy to load standard image datasets. Normalizing images and training a simple CNN helps the model learn useful features, shown by decreasing loss and increasing accuracy over epochs.