YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
πΎ End-to-End Image Classification: Pets vs. Non-Pets
π Project Overview
This project is a complete, end-to-end image classification pipeline designed to distinguish between Pets (Dogs, Cats, Birds, Rabbits) and Non-Pets (Wild Animals, Humans, Objects, Places).
Built using PyTorch and MobileNetV2, the system not only classifies images into broad categories but also provides fine-grained identification, ecological data (dietary habits and natural habitats), and implements intelligent guardrails to ensure accuracy for visually similar wild species.
β¨ Key Features
1. π§ Dual-Model Inference
The system utilizes a powerful two-stage inference process:
- Primary Classifier: A custom-trained MobileNetV2 model that performs the broad classification between "Pets" and "Non-Pets".
- Specific Identifier: A pre-trained ImageNet model that identifies the exact breed or species (e.g., "Golden Retriever", "Egyptian Cat", "Lion").
2. π¦ Wild Animal Guardrails
One of the core strengths of this project is its intelligent override logic. Since wild felines (like lions or tigers) share many visual features with domestic cats, standard models can often misclassify them. This system cross-references the specific identified name with a "Wild Animal" database to force a "Non-Pet" classification for species like:
- Lions, Tigers, Leopards, Cheetahs
- Wolves, Foxes, Bears, Hyenas, and more.
3. π Ecological Information
For every animal identified, the application provides:
- Food Type: Categorized as Herbivorous, Carnivorous, or Omnivorous.
- Habitation: Information about the animal's natural habitat (e.g., "African Savannas", "Domesticated - Human Homes").
4. π¨ Premium Web Interface
A modern, responsive dashboard built with Flask and Vanilla CSS, featuring:
- Drag-and-drop or click-to-upload functionality.
- Real-time result cards with confidence percentages.
- Glassmorphism design aesthetics and smooth micro-animations.
π οΈ Technology Stack
- Framework: PyTorch
- Architecture: MobileNetV2 (Transfer Learning)
- Web Backend: Flask (Python)
- Frontend: HTML5, CSS3 (Modern UI), JavaScript
- Image Processing: Pillow (PIL)
- Deployment: Git/GitHub
π Project Structure
image/
βββ app.py # Flask Web Server & Inference Logic
βββ train.py # PyTorch Training Pipeline
βββ classifier_model.pth # Trained Model Weights
βββ classes.txt # Category Labels
βββ training_history.png # Accuracy/Loss Visualization
βββ static/
β βββ css/style.css # Premium UI Styling
β βββ uploads/ # Temporary storage for uploaded images
βββ templates/
β βββ index.html # Main Dashboard Template
βββ README.md # Project Documentation
π Getting Started
Prerequisites
- Python 3.8+
- PyTorch & Torchvision
- Flask
Installation
Clone the Project
git clone https://github.com/4mh23cs043-collab/image.git cd imageInstall Dependencies
pip install torch torchvision flask pillowLaunch the Application
python app.pyAccess the Dashboard Open your browser and navigate to:
http://127.0.0.1:5001
π Model Training & Results
The model was trained using Transfer Learning on a curated dataset of over 7,000 images. By freezing the early layers of MobileNetV2 and training a custom classification head, we achieved:
- High validation accuracy (>90%).
- Robust performance on diverse animal breeds.
- Low latency inference optimized for CPU environments.
π€ Contribution
This project was developed as a collaborative effort to demonstrate a production-ready AI application. Feel free to fork the repository and submit pull requests for any enhancements!
Created by Nuthan & The AI Pair Programming Team
