High-performance real-time facial emotion recognition system using ResNet50 architecture, trained on FER2013 dataset.
Features β’ Installation β’ Usage β’ Performance β’ Dataset
Emotion_Recognition.mp4
Real-time emotion detection running at 30+ FPS
A production-ready system that identifies 7 distinct facial emotions through webcam feeds in real-time. Built on custom ResNet50 architecture achieving 65.59% validation accuracy on the FER2013 dataset.
|
π Real-time Processing
β‘ High Performance
|
π― Seven Emotions
π οΈ Production Ready
|
Model: Custom ResNet50 with Bottleneck blocks [3, 4, 6, 3]
Input (224Γ224Γ3)
β
Conv2dSame(7Γ7) β BatchNorm β ReLU β MaxPool
β
ResBlock Layer 1 (64 channels)
β
ResBlock Layer 2 (128 channels)
β
ResBlock Layer 3 (256 channels)
β
ResBlock Layer 4 (512 channels)
β
AdaptiveAvgPool β FC(2048β512) β FC(512β7) β Softmax
β
Output (7 emotion classes)
| Parameter | Value |
|---|---|
| Optimizer | Adam (lr=0.001, weight_decay=0.0001) |
| Scheduler | ReduceLROnPlateau (factor=0.5, patience=3) |
| Batch Size | 64 |
| Epochs | 50 |
| Augmentation | Flip, Rotation (Β±15Β°), Brightness/Contrast (0.8-1.2x) |
| Metric | Value | Description |
|---|---|---|
| π― Validation Accuracy | 65.59% | FER2013 test set |
| π Training Accuracy | 80.00% | FER2013 train set |
| β‘ Speed (GPU) | 30+ FPS | NVIDIA GPU (FP16) |
| π» Speed (CPU) | 10-15 FPS | Intel/AMD CPU |
| π¦ Model Size | 90 MB | PyTorch .pt format |
| π’ Parameters | ~23.5M | Trainable params |
|
Dataset Statistics:
|
Emotion Distribution:
|
Note: Images are grayscale 48Γ48 pixels, upscaled to 224Γ224 RGB for training.
β Python 3.8+
β CUDA-compatible GPU (recommended)
β Webcam for real-time inference
1οΈβ£ Clone repository
git clone https://github.com/yourusername/FER2013-ResNet50-Emotion-Recognition.git
cd FER2013-ResNet50-Emotion-Recognition2οΈβ£ Install uv (fast package manager)
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh3οΈβ£ Create environment and install dependencies
uv venv
source venv/bin/activate # Windows: venv\Scripts\activate
uv pip install -r requirements.txt4οΈβ£ Add pre-trained model
Place the trained model file in the models/ directory:
models/FER_static_ResNet50_AffectNet.pt
π‘ Tip: Model file size ~90MB. Available on request or train your own using the notebook.
Run the emotion recognition system:
python realtime_facial_analysis.pyβ¨οΈ Controls: Press q to quit
πΊ Output:
- β Real-time video feed with emotion labels
- π Confidence scores for each prediction
- π― Face bounding boxes with tracking
- β‘ FPS counter for performance monitoring
Open training notebook in Jupyter:
jupyter notebook model_trainign_resnet.ipynbContains: Complete pipeline including data loading, model training, evaluation, and export.
FER2013-ResNet50-Emotion-Recognition/
β
βββ π models/
β βββ FER_static_ResNet50_AffectNet.pt # Trained model weights
β βββ training_curves.png # Training visualization
β
βββ π realtime_facial_analysis.py # Real-time inference script
βββ π model_trainign_resnet.ipynb # Training notebook (Colab/Jupyter)
βββ π requirements.txt # Python dependencies
βββ π« .gitignore # Git ignore rules
βββ π README.md # Documentation
1. Resize to 224Γ224 (INTER_NEAREST)
2. Convert BGR β RGB color space
3. Mean normalization: [R: 91.49, G: 103.88, B: 131.09]
4. Convert to PyTorch tensor (CΓHΓW)| Optimization | Description | Benefit |
|---|---|---|
| FP16 Precision | Half-precision on GPU | 2x faster inference |
| CuDNN Auto-tuning | Optimal conv algorithms | 10-20% speedup |
| Downscaled Detection | 50% resolution for face detection | 50% faster detection |
| Threaded Capture | Non-blocking webcam stream | Eliminates I/O bottleneck |
| Temporal Smoothing | 10-frame moving average | Stable predictions |
Result: 30+ FPS on NVIDIA GPU β’ 10-15 FPS on CPU
If you use this project in your research or applications, please cite:
@software{fer2013_resnet50,
title={Real-Time Facial Emotion Recognition with ResNet50},
author={Your Name},
year={2024},
url={https://github.com/yourusername/FER2013-ResNet50-Emotion-Recognition}
}@inproceedings{goodfellow2013challenges,
title={Challenges in representation learning},
author={Goodfellow, Ian J and others},
booktitle={ICONIP},
year={2013}
}MIT License - see LICENSE file for details.
- FER2013 Dataset - ICML 2013 Challenges in Representation Learning
- ResNet Architecture - He et al., "Deep Residual Learning for Image Recognition"
- MediaPipe - Google's ML solutions for face detection
- PyTorch - Facebook AI Research
Built with β€οΈ using PyTorch and ResNet50
