DEV Community

Quoc Bao
Quoc Bao

Posted on • Updated on

My Pytorch Training Pipeline in Image Classification

On this project, I create a custom dataset of 5 male models and conduct a full Pytorch training pipeline. I use a pretrained model and transfer learning, as well as do hyper-parameter search to help increase the accuracy.

 

✍️ Analysis and Evaluation:

  • Full Pytorch Training Pipeline on Image Classification part1

  • Full Pytorch Training Pipeline on Image Classification part2

📺 My implementations are based off Aladdin Persson and Python Engineer.

 

My repository contains:

  • A training script (using pretrained vgg16 and transfer learning)
  • A script for Hyper-parameter Search
  • A script for loading the model for either resumed training or inference
  • A trained model 😬
  • Some helper functions
  • A dataset

 

📰 Dataset Structure

train/val
|___chau_minh_chi
       |___chau_minh_chi_01.jpg
          |___chau_minh_chi_02.jpg
          ...
|___keita_machida
       |___keita_machida_01.jpg
          |___keita_machida_02.jpg
          ...
Enter fullscreen mode Exit fullscreen mode

 

Small batch visualization

small

 

Large batch visualization

large

 

Visualize the number of classes

class

 

😑 Hyper-parameter Search

Hyper-parameter search

 

💥 Training Epochs

==> Saving new best
Epoch 1/25
Step 34/34, train Loss = 1.84,  train Acc = 0.29
Step 20/20, val loss = 1.58,  val acc = 0.25
Time spent for this epoch -----> 0m 32s

==> Saving new best
Epoch 2/25
Step 34/34, train Loss = 0.91,  train Acc = 0.63
Step 20/20, val loss = 1.53,  val acc = 0.43
Time spent for this epoch -----> 0m 13s

==> Validation accuracy did not improve.
Epoch 3/25
Step 34/34, train Loss = 0.61,  train Acc = 0.82
Step 20/20, val loss = 1.67,  val acc = 0.27
Time spent for this epoch -----> 0m 8s
Enter fullscreen mode Exit fullscreen mode

 

😌 Visualize Loss and Accuracy

Loss and accuracy

 

😅 Accuracy of Each Class

Test Acc
Got 13/30 correct samples over 43.33%
Accuracy of timmy_xu: 33.33%
Accuracy of corbyn_besson: 62.50%
Accuracy of keita_machida: 16.67%
Accuracy of wang_kai: 30.00%
Accuracy of chau_minh_chi: 100.00%
Enter fullscreen mode Exit fullscreen mode

 

😞 Classification Report and Confusion Matrix Heatmap

cm

 

😍 Predict a single image

single

 

😐 Prediction In Batch

In batch

Top comments (0)