Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Matrasulov/Oxford-IIIT-Pet-Dataset---Image-Classification-using-PyTorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐶 Oxford IIIT Pet Dataset - Image Classification using PyTorch

This project demonstrates how to use PyTorch and torchvision to classify pet images from the Oxford-IIIT Pet Dataset using a deep learning model (ReXNet) with transfer learning. It includes data visualization, class balancing insight, training monitoring, and model explainability with Grad-CAM.


📁 Dataset

We use the Oxford-IIIT Pet Dataset, which contains 37 categories (breeds of cats and dogs), with roughly 200 images for each class.

  • ✅ Training Set
  • 🔍 Validation Set
  • 🧪 Test Set

Data is split and preprocessed into PyTorch DataLoaders.


What the Notebook Covers

  1. Data Loading & Preprocessing

    • Loading the dataset using torchvision.datasets.OxfordIIITPet.
    • Applying necessary transformations (resizing, normalization, etc.).
  2. Data Visualization

  • Random Samples from Dataset – to understand image formats and contents.

    gt_plot


  • ⚖️ Class Distribution Charts – visualize imbalance across train, validation, and test sets.

tr_cls_imbalance


val_cls_imbalance


ts_ds_class_imbalance


  • 📉 Training and Validation Accuracy Curves – to monitor learning progress. acc_score


    • 🔍 Grad-CAM Heatmaps - to interpret what regions of the image the model is focusing on. grad_cam_plus


      • 🔀 Confusion Matrix – to evaluate class-wise performance. confusion matrix

🧠 Model Architecture

We use ReXNet v1.5, a lightweight convolutional neural network optimized for efficiency and performance:

  • Backbone: rexnet_150 (loaded from timm)
  • Pretrained: Yes (imagenet)
  • Final Layer: Modified to match the number of pet classes (num_classes=37)
  • Loss: CrossEntropyLoss
  • Metrics: Accuracy and F1Score (torchmetrics.F1Score with multiclass)

🎯 Training Strategy

The training pipeline is built using a custom TrainValidation class:

  • Optimizer: Adam with learning rate = 3e-4
  • Scheduler: ReduceLROnPlateau (monitors validation loss)
  • Early Stopping: Stops training if F1-score doesn’t improve for 3 epochs
  • Epochs: 25 (with early stopping)
  • Best Model Saving: Based on highest F1-Score on validation set
  • Device: GPU (cuda) or CPU fallback
  • Dev Mode: For debugging small runs with dev_mode=True

How to Run the Project

  1. Clone the Repository
    git clone https://github.com/matrasulov/Oxford-IIIT-Pet-Dataset---Image-Classification-using-PyTorch.git
    cd Oxford-IIIT-Pet-Dataset---Image-Classification-using-PyTorch

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.