Skip to content

About

CNN-based facial expression recognition on FER2013+ dataset (8 emotion classes) using residual architecture and focal loss — 82.10% test accuracy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Facial Expression Recognition using CNN

A deep learning project that classifies facial expressions into 8 emotion categories using Convolutional Neural Networks, trained on the FER2013+ dataset.

Overview

This project builds and compares multiple CNN architectures to recognize human facial emotions from grayscale images. The final model uses a residual CNN architecture with focal loss to handle class imbalance, achieving 82.10% test accuracy.

Dataset

  • Dataset: FER2013+ (Facial Expression Recognition)
  • Classes (8): Anger, Contempt, Disgust, Fear, Happiness, Neutral, Sadness, Surprise
  • Image size: 48x48 grayscale
  • Train images: 28,386
  • Test images: 7,099

Approach

The project explores multiple modeling strategies to improve accuracy and handle class imbalance:

Model Technique Accuracy
Model 1 Baseline CNN (3 Conv blocks + BatchNorm + Dropout) 82.00%
Model 2 CNN with Class Weights 75.00%
Model 3 Transfer Learning (MobileNetV2) 58.00%
Model 4 Ensemble (2 CNNs averaged) 45.00%
Model 5 Residual CNN + Focal Loss (Final) 82.10%

Tech Stack

  • Python
  • TensorFlow / Keras
  • NumPy, Pandas
  • Matplotlib, Seaborn
  • Scikit-learn

Model Architecture (Final Model)

  • Convolutional blocks with residual/skip connections
  • Batch Normalization for stable training
  • Dropout for regularization
  • Focal Loss to address class imbalance
  • Data augmentation (rotation, zoom, flip, shift) to improve generalization

Preprocessing Pipeline

  1. Resize images to 48x48
  2. Normalize pixel values (rescale 1./255)
  3. Convert to grayscale
  4. Apply data augmentation (train set only)
  5. Batch the data (batch size = 64)
  6. One-hot encode labels (8 classes)

Evaluation

Model performance was evaluated using:

  • Accuracy
  • Precision, Recall, F1-score (per class)
  • Confusion Matrix

Results

The final residual CNN with focal loss achieved the best overall performance, improving minority class recall while maintaining strong overall accuracy compared to the baseline and other experimental approaches.

Future Improvements

  • Further hyperparameter tuning
  • Larger and more balanced dataset for minority classes (contempt, disgust)
  • Experimenting with attention mechanisms
  • Real-time webcam-based emotion detection

Author

Built as part of exploring deep learning approaches to computer vision problems.

About

CNN-based facial expression recognition on FER2013+ dataset (8 emotion classes) using residual architecture and focal loss — 82.10% test accuracy.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages