A deep learning web application that detects and classifies facial expressions in images. Built with PyTorch and Flask, featuring a ResNet-18 model trained on the RAF-DB dataset achieving 80% accuracy.
December 2025
PythonPyTorchFlaskMTCNNOpenCVResNet-18DockerHugging Face
A deep learning web app that detects and classifies facial expressions in images. Built with PyTorch and Flask, using a ResNet-18 model trained on the RAF-DB dataset at 80% accuracy.
Multi-face Detection: Detects and analyzes multiple faces in a single image
MTCNN Face Detection: Primary detector with Haar Cascade fallback for tough cases
Real-time Visualization: Annotated images with bounding boxes and emotion labels
Confidence Scores: Probability distribution across all emotion classes
Dark/Light Mode: Toggle between themes
Responsive Design: Works on desktop and mobile
What I Did
Face Detection Pipeline
I used a two-stage approach with MTCNN as the primary face detector and Haar Cascade as fallback. MTCNN handles multiple faces in group photos well, and Haar Cascade picks up faces that MTCNN misses (unusual angles, extreme lighting).
Model Training
I used transfer learning with ResNet-18 pretrained on ImageNet and fine-tuned on RAF-DB (Real-world Affective Faces Database), which has 15,339 images across 7 emotion classes. The custom classification head uses batch normalization and dropout for regularization.
Handling Class Imbalance
RAF-DB has serious class imbalance (Happiness: 39%, Fear: 2.3%). I addressed this with focal loss, class weights, and weighted sampling to improve performance on minority classes like Fear and Disgust. The ensemble of models trained with different loss functions ended up being the most effective approach.
Web Application
I built a Flask web app with image upload, real-time emotion detection, and annotated output showing bounding boxes and confidence scores. Deployed on Hugging Face Spaces using Docker.