Skip to content

Umer2900/Cat-vs-Dog-Classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐱🐶 Cat vs Dog Classification System

A complete end-to-end Modular Deep Learning project that performs binary image classification (Cat vs Dog) using multiple CNN architectures.
The project compares custom-built and pre-trained models, selects the best-performing model, and based on classification accuracy, and provides an interactive Streamlit-based user interface for model inference.

🏆 Best Model: ResNet-18
📈 Test Accuracy: 99%
🧠 Models Used: LeNet-5 (from scratch), AlexNet, ResNet-18

🎥 Demo

App Demo


📌 Table of Contents


Why This Project Exists

Most beginner-level Cat vs Dog projects:

  • Use only one pre-trained model
  • Treat CNNs as a black box
  • Lack modular code structure

This project was built to go beyond that.

🎯 Goals of This Project

  • Understand CNN architectures deeply by implementing LeNet-5 from scratch
  • Compare multiple CNN models fairly under the same training conditions
  • Apply software engineering best practices (modularity, reusability)

📌 Focus: Learning-oriented, scalable, and resume-ready Deep Learning project.


🚀 Project Highlights

🧠 Deep Learning & Model Comparison

  • Implemented LeNet-5 CNN architecture from scratch
  • Used AlexNet and ResNet-18 for comparison
  • All models trained for 2 epochs only to ensure fair comparison
  • Best model selected based on validation accuracy

🏆 Best Model Selection

  • ResNet-18 achieved 99% accuracy
  • Automatically selected as the final inference model

⚙️ Modular Codebase

  • Separate modules for:
    • Model definitions
    • Training logic
    • Evaluation
    • Inference
  • Clean, readable, and scalable structure

🌐 Streamlit Web Application

  • Interactive UI for image upload
  • Real-time prediction (Cat or Dog)
  • Lightweight and user-friendly interface

🧠 Models Used

1️⃣ LeNet-5 (From Scratch)

  • Fully implemented CNN architecture
  • Custom convolutional, pooling, and fully connected layers
  • Built for learning and architectural understanding

2️⃣ AlexNet

  • Deeper CNN with higher representational capacity
  • Used for performance comparison

3️⃣ ResNet-18 (Best Model)

  • Residual connections to solve vanishing gradient problem
  • Achieved 99% accuracy
  • Selected as final production model

🔁 Workflow

  1. Data Loading

    • Images loaded from train/test directories
    • Standard preprocessing applied
  2. Model Training

    • Train LeNet-5, AlexNet, and ResNet-18
    • Fixed training epochs (2) for fair comparison
  3. Evaluation

    • Accuracy calculated for each model
    • Best model selected automatically
  4. Inference

    • Saved best model weights
    • Used for real-time prediction in Streamlit app
  5. Deployment

    • Streamlit UI deployed on Streamlit Cloud

🛠️ Technologies Used

Deep Learning & Programming

  • Python
  • PyTorch
  • Torchvision
  • NumPy

Model Architectures

  • LeNet-5 (Custom implementation)
  • AlexNet
  • ResNet-18

Web & Deployment

  • Streamlit – UI development
  • Streamlit Cloud – Deployment platform

Tools

  • Jupyter Notebook – Experiments & training
  • Git & GitHub – Version control

📁 Project Structure

CAT VS DOG CLASSIFIER/

├── configs/

├── models/
│ ├── init.py
│ ├── lenet5.py
│ └── model_factory.py ← Factory of models (LeNet, alexnet, ResNet)

├── NoteBook/
│ ├── Cat_vs_Dog_Classifier.ipynb

├── training/
│ ├── init.py
│ ├── evaluate.py
│ ├── train_all_models.py
│ └── train_utils.py


├── .gitignore
├── app.py ← Application entry point
├── inference.py
├── README.md
└── requirements.txt


Setup Instructions

Prerequisites

To run this project locally, ensure you have the following installed:

  • Python 3.8+
  • Git
  • Virtual environemnt (recommended)

Steps

  1. Clone the Repository:

    git clone https://github.com/Umer2900/Cat-vs-Dog-Classifier
    cd Cat-vs-Dog-Classifier
  2. Install Dependencies:

    python -m venv venv
    venv\Scripts\activate       # Windows
  3. Install Streamlit App:

    pip install -r requirements.txt
  4. Run the Application:

    streamlit run app.py

    The app will be available at 🌐 http://localhost:8501.


About

A complete **End-to-End Modular Deep Learning project**

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors