abdelrhman145's picture
Update README.md
df86537 verified
metadata
title: Facial Emotion Recognition
emoji: 😊
colorFrom: blue
colorTo: pink
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false

😊 Facial Emotion Recognition (EfficientNet-B4 + Focal Loss + MixUp/CutMix)

This project demonstrates Facial Emotion Recognition using a fine-tuned EfficientNet-B4 model trained on a balanced subset of the AffectNet dataset.

It can detect the emotion of a person from:

  • πŸ“Έ Uploaded images
  • πŸŽ₯ Live camera feed

🧠 Model Overview

Feature Description
Base Model EfficientNet-B4 (from timm library)
Loss Function Focal Loss (Ξ³=2, Ξ±=1)
Regularization MixUp & CutMix augmentations
Optimizer AdamW with CosineAnnealingLR
Input Size 224Γ—224
Classes Anger, Contempt, Disgust, Fear, Happy, Neutral, Sad, Surprise

These techniques were introduced to reduce overfitting and enhance model generalization, achieving higher validation accuracy compared to a baseline model using standard CrossEntropyLoss.


πŸ“Š Performance Summary

Metric Baseline (CE Loss) Improved Model (Focal + MixUp/CutMix)
Train Accuracy 97.8% 60.6%
Val Accuracy 77.2% 79.2%
Val F1 Score 0.77 0.79
Early Stopping No βœ… Yes
Overfitting ❌ Present βœ… Reduced

Note: The validation accuracy surpasses the training accuracy in the improved model, indicating successful regularization and harder training augmentations that improve generalization.


βš™οΈ Usage

πŸ“Έ Upload Image

Upload an image containing a face β€” the model will detect the face, draw a bounding box, and display the predicted emotion label.

πŸŽ₯ Live Camera

Activate your webcam to detect emotions in real-time. The bounding box and emotion label are updated continuously.


🧩 Tech Stack

  • Python 3.10+
  • PyTorch (for model training & inference)
  • Timm (for EfficientNet backbone)
  • OpenCV (for face detection)
  • Gradio (for the web interface)
  • NumPy, Pillow, Seaborn, Matplotlib (for visualization & preprocessing)

πŸ“‚ Dataset

The model was trained using a balanced subset of the AffectNet dataset, resized to 224Γ—224 with approximately 3,690 images per class.
Augmentations included random flips, color jitter, and light rotations to preserve facial expression semantics.


πŸ‘¨β€πŸ’» Authors

Developed by:

  • Abdelrhman Khaled Hassan

As part of an academic research project exploring emotion classification and regularization techniques in deep learning.


πŸ“š References


🌐 Live Demo

Once deployed, your live demo will be available at:

https://huggingface.co/spaces/abdelrhman145/Face_Emotion_Recognition