Skip to content

AahanKotian/Image-Classifier-with-Deep-Learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–ΌοΈ Deep Learning Image Classifier

A full-stack deep learning project featuring a Convolutional Neural Network (CNN) trained on image classification tasks, with a polished drag-and-drop web UI for real-time inference.

Python TensorFlow Flask License


🎯 What This Project Demonstrates

Skill Implementation
CNNs Custom Conv2D β†’ MaxPool β†’ Dropout β†’ Dense architecture
Transfer Learning MobileNetV2 fine-tuning on custom datasets
Data Augmentation Random flip, rotation, zoom via tf.keras.layers
Model Serialization SavedModel + TFLite export for web deployment
REST API Flask endpoint serving predictions with confidence scores
Modern Web UI Drag-and-drop canvas with real-time TensorFlow.js inference

πŸ—οΈ Project Structure

image-classifier/
β”œβ”€β”€ model/
β”‚   β”œβ”€β”€ train.py              # CNN training script (MNIST / CIFAR-10)
β”‚   β”œβ”€β”€ transfer_learning.py  # MobileNetV2 fine-tuning
β”‚   β”œβ”€β”€ evaluate.py           # Metrics, confusion matrix, grad-cam
β”‚   └── saved/                # Exported .h5 and SavedModel artifacts
β”œβ”€β”€ web/
β”‚   β”œβ”€β”€ app.py                # Flask API server
β”‚   β”œβ”€β”€ static/
β”‚   β”‚   β”œβ”€β”€ css/style.css     # UI styles
β”‚   β”‚   └── js/classifier.js  # TensorFlow.js client inference
β”‚   └── templates/
β”‚       └── index.html        # Drag-and-drop UI
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ preprocess.py         # Image pipeline helpers
β”‚   └── dataset.py            # Dataset loaders
β”œβ”€β”€ notebooks/
β”‚   └── exploration.ipynb     # EDA and training walkthrough
β”œβ”€β”€ tests/
β”‚   └── test_model.py         # Unit tests
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ Dockerfile
└── README.md

πŸš€ Quick Start

1. Clone & Install

git clone https://github.com/yourusername/image-classifier.git
cd image-classifier
python -m venv venv
source venv/bin/activate      # Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Train the Model

# Train on MNIST (fast β€” ~2 min on CPU)
python model/train.py --dataset mnist --epochs 10

# Train on CIFAR-10 (recommended β€” ~15 min on GPU)
python model/train.py --dataset cifar10 --epochs 25

# Fine-tune MobileNetV2 on a custom folder of images
python model/transfer_learning.py --data_dir ./my_images --epochs 10

3. Launch the Web UI

cd web
python app.py
# Open http://localhost:5000

4. Run with Docker

docker build -t image-classifier .
docker run -p 5000:5000 image-classifier

🧠 Model Architecture

Custom CNN (MNIST / CIFAR-10)

Input (28x28x1 or 32x32x3)
  β”‚
  β”œβ”€ Conv2D(32, 3x3, relu) β†’ BatchNorm β†’ MaxPool(2x2)
  β”œβ”€ Conv2D(64, 3x3, relu) β†’ BatchNorm β†’ MaxPool(2x2)
  β”œβ”€ Conv2D(128, 3x3, relu) β†’ BatchNorm
  β”‚
  β”œβ”€ GlobalAveragePooling2D
  β”œβ”€ Dense(256, relu) β†’ Dropout(0.4)
  └─ Dense(num_classes, softmax)

Transfer Learning (Custom Datasets)

MobileNetV2 (ImageNet weights, frozen)
  β”‚
  β”œβ”€ GlobalAveragePooling2D
  β”œβ”€ Dense(128, relu) β†’ Dropout(0.3)
  └─ Dense(num_classes, softmax)

Training Results (CIFAR-10):

  • Test Accuracy: ~91%
  • Parameters: 2.3M (custom CNN), 3.5M (MobileNetV2)

πŸ“Š Key Learning Concepts

Convolutional Neural Networks

CNNs use learnable filters that slide over the image, detecting edges β†’ textures β†’ shapes β†’ objects at increasing abstraction levels. Each Conv2D layer learns these filters automatically from data.

Transfer Learning

Instead of training from scratch, we use MobileNetV2 pre-trained on 1.4M ImageNet images. We freeze early layers (which learned universal features like edges) and only fine-tune later layers on our specific classes. This works well with as few as 100–500 images per class.

Data Augmentation

Randomly flipping, rotating, and zooming training images creates artificial variety, reducing overfitting β€” the model learns the object, not the exact pixels.


🌐 API Reference

POST /predict

curl -X POST http://localhost:5000/predict \
  -F "image=@test_image.jpg"
{
  "prediction": "cat",
  "confidence": 0.9423,
  "top_k": [
    {"class": "cat",  "confidence": 0.9423},
    {"class": "dog",  "confidence": 0.0511},
    {"class": "bird", "confidence": 0.0066}
  ],
  "inference_time_ms": 12.4
}

πŸ”§ Customizing for Your Own Dataset

my_images/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ cat/     (β‰₯100 images)
β”‚   β”œβ”€β”€ dog/     (β‰₯100 images)
β”‚   └── bird/    (β‰₯100 images)
└── val/
    β”œβ”€β”€ cat/
    β”œβ”€β”€ dog/
    └── bird/

Then run:

python model/transfer_learning.py --data_dir ./my_images --epochs 15

πŸ§ͺ Tests

pytest tests/ -v

πŸ“ˆ Future Improvements

  • Grad-CAM visualizations (see what the model "looks at")
  • ONNX export for cross-platform deployment
  • React frontend with webcam capture
  • Model quantization for mobile (TFLite)
  • CI/CD with GitHub Actions

πŸ“„ License

MIT License β€” see LICENSE

About

A full-stack deep learning project featuring a Convolutional Neural Network (CNN) trained on image classification tasks, with a polished drag-and-drop web UI for real-time inference.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors