Skip to content

A deep learning project for real-time face detection, emotion recognition, and facial identification using CNNs, implemented during my engineering internship at LEONI WIRING SYSTEMS.

Notifications You must be signed in to change notification settings

sary05sys/Facial-Sentiment-Analysis-using-CNN

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

6 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Facial Sentiment Analysis using Convolutional Neural Network (CNN)

Python
TensorFlow
OpenCV
License

๐Ÿ“Œ Table of Contents


๐ŸŒŸ Project Background

Year: 2022-2023 (Engineering Internship)
Supervisor: Mr. Bassem Hmissa (LEONI WIRING SYSTEMS)
Institution: National School of Electronics and Telecommunications of Sfax, Tunisia

๐ŸŽฏ Motivation

Commercial APIs (e.g., Microsoft Face API) treat facial analysis as a "black box," limiting customization and interpretability. This project was developed to:

  • Demystify AI models by building face detection, emotion recognition, and facial identification systems from scratch.
  • Analyze hyperparameter impact (epochs, batch size, optimizers) on model accuracy.
  • Provide a flexible SaaS solution adaptable to client-specific datasets.

๐Ÿš€ Key Features

1. Face Detection

  • Haar Cascade: Real-time detection using OpenCV.
  • YOLOv4: Higher accuracy (94.82%) but sensitive to face angles/lighting.
    • Limitations: Struggles with rotated faces (-2) and color resemblance (-1.

2. Emotion Detection

  • 7-class CNN (angry, disgust, fear, happy, neutral, sad, surprise).
  • Dataset: FER-2013 (35,887 images, 48x48px).
  • Best Model:
    Model.add(ZeroPadding2D())  
    Model.add(Conv2D(32, (3,3), activation='relu'))  
    Model.add(MaxPooling2D())  
    Model.add(Dense(7, activation='softmax'))  

3. Facial Recognition

  • Dataset: LFW (13,233 images) + custom-injected faces.
  • Custom CNN: Achieved 76.34% training accuracy.

๐Ÿ› ๏ธ Technologies Used

Category Tools/Libraries
Frameworks TensorFlow, Keras, Darknet (YOLOv4)
Computer Vision OpenCV, PIL
Data Processing NumPy, Pandas, Matplotlib
Environment Google Colab, Kaggle API

๐Ÿ“ฆ Installation

  1. Clone the repository:
    git clone https://github.com/mariam-khediri/Facial-Sentiment-Analysis-using-CNN.git  
    cd facial-sentiment-analysis  
  2. Install dependencies:
    pip install -r requirements.txt  # Sample requirements.txt included below  
    requirements.txt:
    tensorflow==2.8.2  
    opencv-python==4.6.0  
    numpy>=1.21.0  
    matplotlib>=3.5.0  
    
  3. Download pretrained models:

๐Ÿ–ฅ๏ธ Usage

Real-Time Emotion Detection

python emotion_detection.py --mode=camera  

Output:

  • Processes webcam feed โ†’ detects faces โ†’ predicts emotions (image ).
  • Supports image input: --image=test.jpg.

Facial Recognition

python facial_recognition.py --dataset=lfw --epochs=120  

Output:

  • Recognizes faces from LFW dataset or custom-injected images image

๐Ÿ“Š Detailed Results

Emotion Detection (CNN)

Hyperparameter Best Value Accuracy (Train/Test)
Optimizer Adam (lr=0.001) 94% / 51%
Epochs 30 94.75% (Train)
Batch Size 64 47.38% (Test)

Key Observations:

  • Higher epochs โ†’ overfitting (test loss โ†‘ to 6.21).
  • SGD optimizer underperformed (max 25.83% test accuracy).

Facial Recognition (Custom CNN)

Batch Size Epochs Train Accuracy Test Accuracy
64 120 76.34% 14.32%
32 25 32.37% 10.34%

Challenges:

  • Low test accuracy due to dataset complexity (5,749 identities).
  • Dropout layers reduced overfitting (image vs image ).

๐Ÿ”ฎ Future Work

  • Data Augmentation: Improve test accuracy with transformations (rotation, scaling).
  • Transformer Models: Experiment with Vision Transformers (ViT).
  • API Deployment: Flask/Django backend for SaaS integration.

๐Ÿ™ Acknowledgments

  • Professional Supervisor: Mr. Bassem Hmissa (LEONI).
  • Dataset Providers: Kaggle (FER-2013, LFW).
  • Institutional Support: Sfax University, Tunisia.

๐Ÿ“œ License

MIT ยฉ Mariem Khedhiri

About

A deep learning project for real-time face detection, emotion recognition, and facial identification using CNNs, implemented during my engineering internship at LEONI WIRING SYSTEMS.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%