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.
| 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 |
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
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# 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 10cd web
python app.py
# Open http://localhost:5000docker build -t image-classifier .
docker run -p 5000:5000 image-classifierInput (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)
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)
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.
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.
Randomly flipping, rotating, and zooming training images creates artificial variety, reducing overfitting β the model learns the object, not the exact pixels.
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
}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 15pytest tests/ -v- 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
MIT License β see LICENSE