Skip to content

About

A deep learning facial emotion classification system using CNN, VGG16, and ResNet50V2. The project includes image preprocessing, augmentation, class balancing, transfer learning, model evaluation, confusion matrix, ROC analysis, and an interactive Gradio interface for emotion prediction.

Resources

Stars

135 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

112 Commits

Folders and files

Repository files navigation

๐Ÿง  Facial Emotion Classification Using Deep Learning

A Deep Learning-based Facial Emotion Classification System using CNN, VGG16, and ResNet50V2 Transfer Learning

Overview โ€ข Features โ€ข Architecture โ€ข Models โ€ข Dataset โ€ข Evaluation โ€ข Deployment โ€ข Installation


๐Ÿ“Œ Project Overview

This project implements a Deep Learning Facial Emotion Classification system capable of classifying facial expressions into seven emotion categories.

The project explores multiple deep learning approaches, beginning with a custom Convolutional Neural Network (CNN) and progressing toward Transfer Learning using pretrained VGG16 and ResNet50V2 architectures.

The final workflow includes:

  • ๐Ÿ–ผ๏ธ Facial image preprocessing
  • ๐Ÿ”„ Image augmentation
  • โš–๏ธ Class-weight balancing
  • ๐Ÿง  Custom CNN architecture
  • ๐Ÿš€ VGG16 transfer learning
  • โšก ResNet50V2 transfer learning
  • ๐Ÿ“Š Confusion matrix analysis
  • ๐Ÿ“‹ Classification reports
  • ๐Ÿ“ˆ ROC curve analysis
  • ๐Ÿ’พ Model checkpointing
  • ๐Ÿงช Model evaluation
  • ๐ŸŒ Gradio-based image prediction interface

The trained ResNet50V2 model is also prepared for deployment, allowing users to upload an image and obtain a predicted facial emotion.


๐ŸŽฏ Objectives

The primary objectives of this project are to:

  1. Develop a deep learning model for facial emotion classification.
  2. Compare different CNN-based architectures.
  3. Investigate the effectiveness of transfer learning.
  4. Apply image augmentation to improve model generalization.
  5. Address class imbalance through class weighting.
  6. Evaluate models using multiple classification metrics.
  7. Analyze prediction errors using confusion matrices.
  8. Examine class-wise ROC performance.
  9. Save trained models for later use.
  10. Build an interactive prediction interface using Gradio.

๐Ÿ˜Š Emotion Classes

The system classifies facial expressions into 7 emotion categories:

Class Emotion
๐Ÿ˜  Angry
๐Ÿคข Disgust
๐Ÿ˜จ Fear
๐Ÿ˜„ Happy
๐Ÿ˜ Neutral
๐Ÿ˜ข Sad
๐Ÿ˜ฒ Surprise

Label Mapping

0 โ†’ Angry
1 โ†’ Disgust
2 โ†’ Fear
3 โ†’ Happy
4 โ†’ Neutral
5 โ†’ Sad
6 โ†’ Surprise

๐Ÿ—๏ธ Project Architecture

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚     Facial Images       โ”‚
                    โ”‚      Train / Test       โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Image Preprocessing   โ”‚
                    โ”‚  Resize + Normalization โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Data Augmentation     โ”‚
                    โ”‚ Rotation / Zoom / Shift โ”‚
                    โ”‚    Horizontal Flip      โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    Class Balancing      โ”‚
                    โ”‚      Class Weights      โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                  โ”‚              โ”‚              โ”‚
                  โ–ผ              โ–ผ              โ–ผ
             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
             โ”‚  CNN   โ”‚    โ”‚ VGG16   โ”‚    โ”‚ ResNet50V2 โ”‚
             โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                  โ”‚              โ”‚              โ”‚
                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚       Evaluation        โ”‚
                    โ”‚ Accuracy / Confusion    โ”‚
                    โ”‚ Matrix / Classification โ”‚
                    โ”‚ Report / ROC Analysis   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Trained Model (.keras)โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                                 โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    Gradio Interface     โ”‚
                    โ”‚    Upload Image โ†’       โ”‚
                    โ”‚    Emotion Prediction   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


๐Ÿ”ฌ Deep Learning Models

The notebook experiments with three major approaches.

1๏ธโƒฃ Custom CNN

The project first develops a custom convolutional neural network containing multiple convolutional blocks.

The architecture includes:

  • Conv2D
  • ReLU activation
  • Batch Normalization
  • Max Pooling
  • Dropout
  • L2 regularization
  • Fully connected layers
  • Softmax output layer

The CNN processes facial images at 48 ร— 48 resolution with a grayscale input configuration.

Input Image
     โ”‚
     โ–ผ
Conv2D 32
     โ”‚
     โ–ผ
Conv2D 64
     โ”‚
     โ–ผ
Batch Normalization
     โ”‚
     โ–ผ
Max Pooling
     โ”‚
     โ–ผ
Dropout
     โ”‚
     โ–ผ
Conv2D 128
     โ”‚
     โ–ผ
Conv2D 256
     โ”‚
     โ–ผ
Batch Normalization
     โ”‚
     โ–ผ
Max Pooling
     โ”‚
     โ–ผ
Conv2D 512
     โ”‚
     โ–ผ
Classification

๐Ÿš€ 2๏ธโƒฃ VGG16 Transfer Learning

The second major approach uses VGG16 pretrained on ImageNet.

Images are resized to:

224 ร— 224 ร— 3

The pretrained VGG16 convolutional base is used as a feature extractor, with selected layers made trainable for fine-tuning.

Custom Classification Head

VGG16
  โ”‚
  โ–ผ
Flatten
  โ”‚
  โ–ผ
Dense 1024 + ReLU
  โ”‚
  โ–ผ
Dropout 0.5
  โ”‚
  โ–ผ
Dense 512 + ReLU
  โ”‚
  โ–ผ
Dropout 0.5
  โ”‚
  โ–ผ
Dense 7 + Softmax

The model uses:

  • ImageNet pretrained weights
  • Fine-tuning
  • Adam optimizer
  • Categorical cross-entropy
  • Dropout regularization
  • Class weighting

โšก 3๏ธโƒฃ ResNet50V2 Transfer Learning

The project also implements ResNet50V2 using ImageNet pretrained weights.

The model is partially fine-tuned by freezing earlier layers and allowing the final portion of the network to train.

ResNet50V2 Architecture

Input Image
     โ”‚
     โ–ผ
ResNet50V2
     โ”‚
     โ–ผ
Dropout 0.25
     โ”‚
     โ–ผ
Batch Normalization
     โ”‚
     โ–ผ
Flatten
     โ”‚
     โ–ผ
Dense 64 + ReLU
     โ”‚
     โ–ผ
Batch Normalization
     โ”‚
     โ–ผ
Dropout 0.5
     โ”‚
     โ–ผ
Dense 7 + Softmax
     โ”‚
     โ–ผ
Emotion Prediction

The notebook saves the trained model as:

ResNet50_Transfer_Learning.keras

and also creates:

Resnet_model_version_2.keras

๐Ÿ—‚๏ธ Dataset Structure

The repository contains separate training and testing directories.

๐Ÿ“ฆ Project
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ train/
โ”‚   โ”œโ”€โ”€ angry/
โ”‚   โ”œโ”€โ”€ disgust/
โ”‚   โ”œโ”€โ”€ fear/
โ”‚   โ”œโ”€โ”€ happy/
โ”‚   โ”œโ”€โ”€ neutral/
โ”‚   โ”œโ”€โ”€ sad/
โ”‚   โ””โ”€โ”€ surprise/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ test/
โ”‚   โ”œโ”€โ”€ angry/
โ”‚   โ”œโ”€โ”€ disgust/
โ”‚   โ”œโ”€โ”€ fear/
โ”‚   โ”œโ”€โ”€ happy/
โ”‚   โ”œโ”€โ”€ neutral/
โ”‚   โ”œโ”€โ”€ sad/
โ”‚   โ””โ”€โ”€ surprise/
โ”‚
โ”œโ”€โ”€ ๐Ÿ““ Deep Learning Model for Facial Emotion Classification.ipynb
โ””โ”€โ”€ ๐Ÿ“„ README.md

The notebook uses directory-based image loading with Keras ImageDataGenerator.


๐Ÿงน Data Preprocessing

The project performs several preprocessing operations before model training.

Image Resizing

For the custom CNN:

48 ร— 48

For transfer-learning models:

224 ร— 224

Pixel Normalization

Pixel values are rescaled from:

0โ€“255

to:

0โ€“1

using:

rescale = 1 / 255.

๐Ÿ”„ Data Augmentation

Training images are augmented using transformations such as:

Augmentation Configuration
Rotation ยฑ10ยฐ
Zoom 0.2
Width Shift 0.1
Height Shift 0.1
Horizontal Flip Enabled
Fill Mode Nearest

The purpose is to expose the model to variations in facial appearance and reduce dependence on exact training-image configurations.


โš–๏ธ Class Imbalance Handling

The notebook calculates balanced class weights using:

compute_class_weight(
    class_weight='balanced'
)

The resulting weights are supplied during model training:

class_weight=class_weights_dict

This gives the training process a mechanism to account for differences in the number of images available for each emotion class.


๐Ÿงช Training Strategy

The project uses several training techniques to improve model training and generalization.

Training Components

โœ” Image Augmentation
โœ” Class Weighting
โœ” Transfer Learning
โœ” Fine-Tuning
โœ” Dropout
โœ” Batch Normalization
โœ” L2 Regularization
โœ” Early Stopping
โœ” Learning Rate Reduction
โœ” Model Checkpointing
โœ” Training Log Generation

๐Ÿ›ก๏ธ Training Callbacks

The transfer-learning experiments use callbacks including:

๐Ÿ’พ ModelCheckpoint

Saves the best-performing model according to validation loss.

โน๏ธ EarlyStopping

Stops training when monitored validation performance does not improve according to the configured patience.

๐Ÿ“‰ ReduceLROnPlateau

Reduces the learning rate when validation performance stops improving.

๐Ÿ“‹ CSVLogger

Stores training information in a log file.


๐Ÿ“Š Model Evaluation

The project does not rely exclusively on accuracy.

Multiple evaluation techniques are implemented:

๐Ÿ“ˆ Accuracy

Measures the proportion of correctly classified samples.

๐Ÿ“‹ Classification Report

The notebook generates class-level:

  • Precision
  • Recall
  • F1-score
  • Support

๐Ÿ”ฒ Confusion Matrix

The confusion matrix provides a class-by-class view of:

Actual Emotion
      โ†“
Predicted Emotion

This helps identify which emotions are frequently confused by the model.

๐Ÿ“ˆ ROC Analysis

The project also calculates ROC curves and AUC values for the seven emotion classes.


๐Ÿ” Evaluation Workflow

                    Trained Model
                         โ”‚
                         โ–ผ
                  Test Dataset
                         โ”‚
              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
              โ”‚          โ”‚          โ”‚
              โ–ผ          โ–ผ          โ–ผ
          Accuracy   Confusion   Classification
                      Matrix       Report
              โ”‚          โ”‚          โ”‚
              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                         โ”‚
                         โ–ผ
                    ROC Analysis

๐Ÿง  Model Development Journey

The notebook follows an incremental deep learning workflow:

                    Facial Emotion Dataset
                              โ”‚
                              โ–ผ
                     Custom CNN Model
                              โ”‚
                              โ–ผ
                      Model Evaluation
                              โ”‚
                              โ–ผ
                     Data Augmentation
                              โ”‚
                              โ–ผ
                      VGG16 Transfer
                              โ”‚
                              โ–ผ
                       VGG Evaluation
                              โ”‚
                              โ–ผ
                    ResNet50V2 Transfer
                              โ”‚
                              โ–ผ
                  Fine-Tuning + Evaluation
                              โ”‚
                              โ–ผ
                    Saved Keras Model
                              โ”‚
                              โ–ผ
                    Gradio Deployment

๐ŸŒ Deployment

The project includes an interactive Gradio prediction workflow.

The saved ResNet50V2 model is loaded and used for inference.

Prediction Pipeline

          ๐Ÿ“ท User Image
                โ”‚
                โ–ผ
        Image Preprocessing
                โ”‚
                โ–ผ
          Resize 224ร—224
                โ”‚
                โ–ผ
        Normalize Pixel Values
                โ”‚
                โ–ผ
          ResNet50V2 Model
                โ”‚
                โ–ผ
        Softmax Probabilities
                โ”‚
                โ–ผ
       Highest Probability Class
                โ”‚
                โ–ผ
       ๐Ÿ˜Š Emotion Prediction

The deployment code maps the model's numerical output back to the corresponding emotion label.


๐Ÿ–ฅ๏ธ Gradio Interface

The notebook prepares a Gradio-based interface where a user can upload an image.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          ๐Ÿง  FACIAL EMOTION AI              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                             โ”‚
โ”‚        ๐Ÿ“ท Upload Facial Image               โ”‚
โ”‚                                             โ”‚
โ”‚              [ Upload ]                     โ”‚
โ”‚                                             โ”‚
โ”‚                 โ†“                           โ”‚
โ”‚                                             โ”‚
โ”‚        ๐Ÿค– Deep Learning Model               โ”‚
โ”‚                                             โ”‚
โ”‚                 โ†“                           โ”‚
โ”‚                                             โ”‚
โ”‚       ๐ŸŽฏ Predicted Emotion                  โ”‚
โ”‚                                             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ› ๏ธ Technology Stack

Technology Purpose
๐Ÿ Python Programming Language
๐Ÿง  TensorFlow Deep Learning Framework
๐Ÿ”ฅ Keras Neural Network Development
๐Ÿ‘๏ธ OpenCV Computer Vision
๐Ÿ–ผ๏ธ PIL Image Processing
๐Ÿ“Š NumPy Numerical Computing
๐Ÿผ Pandas Data Processing
๐Ÿ“ˆ Matplotlib Visualization
๐ŸŽจ Seaborn Statistical Visualization
๐Ÿค— Gradio Interactive Deployment
โ˜๏ธ Google Colab Model Development Environment

๐Ÿ“ Repository Structure

๐Ÿ“ฆ Facial-Emotion-Classification
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ train/
โ”‚   โ”œโ”€โ”€ angry/
โ”‚   โ”œโ”€โ”€ disgust/
โ”‚   โ”œโ”€โ”€ fear/
โ”‚   โ”œโ”€โ”€ happy/
โ”‚   โ”œโ”€โ”€ neutral/
โ”‚   โ”œโ”€โ”€ sad/
โ”‚   โ””โ”€โ”€ surprise/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ test/
โ”‚   โ”œโ”€โ”€ angry/
โ”‚   โ”œโ”€โ”€ disgust/
โ”‚   โ”œโ”€โ”€ fear/
โ”‚   โ”œโ”€โ”€ happy/
โ”‚   โ”œโ”€โ”€ neutral/
โ”‚   โ”œโ”€โ”€ sad/
โ”‚   โ””โ”€โ”€ surprise/
โ”‚
โ”œโ”€โ”€ ๐Ÿ““ Deep Learning Model for Facial Emotion Classification.ipynb
โ”‚
โ”œโ”€โ”€ ๐Ÿง  ResNet50_Transfer_Learning.keras
โ”‚
โ”œโ”€โ”€ ๐Ÿง  Resnet_model_version_2.keras
โ”‚
โ””โ”€โ”€ ๐Ÿ“„ README.md

Note: Keep the actual repository structure synchronized with the files you have uploaded to GitHub. The model files above are included in the README structure only if they are present in your repository.


๐Ÿš€ Installation

Clone the repository:

git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git

Move into the project directory:

cd YOUR-REPOSITORY

Install the required libraries:

pip install tensorflow
pip install numpy pandas matplotlib seaborn
pip install opencv-python pillow
pip install scikit-learn
pip install gradio

โ–ถ๏ธ Running the Project

Option 1 โ€” Google Colab

Upload the notebook to Google Colab and make sure the dataset directories are available at the paths expected by the notebook.

The notebook currently uses paths such as:

/content/train
/content/test

Run the notebook cells sequentially.


Option 2 โ€” Local Environment

Place the dataset folders in the project directory:

project/
โ”œโ”€โ”€ train/
โ”œโ”€โ”€ test/
โ””โ”€โ”€ notebook.ipynb

Then update the dataset paths in the notebook if required.


๐Ÿ”ฌ Experimental Components

The notebook demonstrates several important deep learning concepts:

                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ Facial Image Data   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ”‚
             โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
             โ–ผ                 โ–ผ                 โ–ผ
       Preprocessing     Augmentation      Class Weighting
             โ”‚                 โ”‚                 โ”‚
             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                               โ–ผ
                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚ Deep Learning   โ”‚
                     โ”‚ Model Training  โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                โ–ผ             โ–ผ             โ–ผ
               CNN          VGG16       ResNet50V2
                โ”‚             โ”‚             โ”‚
                โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ–ผ
                        Evaluation
                              โ”‚
                              โ–ผ
                         Deployment

๐Ÿ’ก Key Learning Outcomes

This project demonstrates practical experience with:

  • Convolutional Neural Networks
  • Transfer Learning
  • Image Classification
  • Fine-Tuning pretrained networks
  • TensorFlow/Keras
  • Image augmentation
  • Class imbalance handling
  • Model regularization
  • Model checkpointing
  • Early stopping
  • Learning-rate scheduling
  • Classification metrics
  • Confusion matrix interpretation
  • ROC/AUC analysis
  • Model serialization
  • Interactive AI deployment

๐Ÿ“Œ Important Implementation Details

Custom CNN

Input โ†’ 48ร—48ร—1

Transfer Learning Models

Input โ†’ 224ร—224ร—3

Number of Classes

7

Output Activation

Softmax

Loss Function

Categorical Cross-Entropy

Main Optimizers

Adam

๐Ÿ“Š Evaluation Dashboard

Evaluation Component Implemented
Training Accuracy โœ…
Test/Validation Accuracy โœ…
Precision โœ…
Recall โœ…
F1-Score โœ…
Confusion Matrix โœ…
Classification Report โœ…
ROC Curve โœ…
AUC โœ…
Class Weighting โœ…
Data Augmentation โœ…
Model Checkpointing โœ…

๐ŸŽฏ Project Highlights

๐Ÿง  Models ๐Ÿ˜Š Classes ๐Ÿ–ผ๏ธ Input ๐Ÿš€ Deployment
CNN โ€ข VGG16 โ€ข ResNet50V2 7 48ร—48 / 224ร—224 Gradio


๐Ÿ”ฎ Future Improvements

Potential future extensions include:

  • Real-time webcam emotion recognition
  • Face detection before emotion classification
  • More extensive hyperparameter optimization
  • Cross-validation experiments
  • Additional pretrained architectures
  • Ensemble learning
  • Model explainability using Grad-CAM
  • Confidence-score visualization
  • Improved handling of minority emotion classes
  • Mobile or web application deployment
  • API-based inference
  • Model quantization for lightweight deployment

โš ๏ธ Limitations

The notebook represents an experimental deep learning workflow and includes multiple model configurations.

Some implementation choices are environment-specific, particularly the Google Colab paths and Google Drive model-storage paths.

The test directory is used as validation/evaluation data in parts of the notebook, so users should distinguish between validation during model development and a completely independent held-out test set when reporting final experimental results.


๐Ÿ‘จโ€๐Ÿ’ป About Me

Shahid Azam

MS Computer Science Student Specialization in Artificial Intelligence

Institute of Management Sciences, Peshawar, Pakistan

I enjoy building complete software systemsโ€”from networking and operating system concepts to backend architecture, machine learning, and distributed systems.

  • ๐ŸŽ“ Degree / Field: MS in Computer Science (Specialization in Artificial Intelligence)
  • ๐Ÿ† Achievements: Designed and executed 30+ machine learning and data visualization projects delivering actionable insights
  • ๐ŸŽฏ Focus Areas: Data Visualization, AI/ML, Big Data Mining
  • ๐Ÿ“ฌ Contact: shahidazam2020@gmail.com
  • WhatsApp: Chat on WhatsApp

๐Ÿค Connect With Me


โญ Repository

If you find this project useful for learning or experimentation, consider giving the repository a โญ.

โญ Star this repository โ€ข ๐Ÿด Fork it โ€ข ๐Ÿง  Explore the code โ€ข ๐Ÿš€ Build something new


๐Ÿ“œ License

This project is intended for educational, research, and experimental purposes.

If you reuse or extend this project, please provide appropriate attribution to the original work and dataset sources where applicable.


๐Ÿง  From Facial Images โ†’ Deep Learning โ†’ Emotion Intelligence

Built with Python, TensorFlow & Computer Vision


โญ Support

If you find this repository useful for learning Machine Learning, consider giving it a โญ.

Your feedback, suggestions, and contributions are welcome.


๐Ÿง  Learn Machine Learning โ€ข ๐Ÿ’ป Build Models โ€ข ๐Ÿ“Š Analyze Data โ€ข ๐Ÿš€ Create Projects

Made with โค๏ธ for learning, experimentation, and continuous improvement.

About

A deep learning facial emotion classification system using CNN, VGG16, and ResNet50V2. The project includes image preprocessing, augmentation, class balancing, transfer learning, model evaluation, confusion matrix, ROC analysis, and an interactive Gradio interface for emotion prediction.

Resources

Stars

135 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages