- Project Background
- Key Features
- Technologies Used
- Installation
- Usage
- Detailed Results
- Future Work
- Acknowledgments
- License
Year: 2022-2023 (Engineering Internship)
Supervisor: Mr. Bassem Hmissa (LEONI WIRING SYSTEMS)
Institution: National School of Electronics and Telecommunications of Sfax, Tunisia
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.
- Haar Cascade: Real-time detection using OpenCV.
- YOLOv4: Higher accuracy (94.82%) but sensitive to face angles/lighting.
- 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'))
- Dataset: LFW (13,233 images) + custom-injected faces.
- Custom CNN: Achieved 76.34% training accuracy.
Category | Tools/Libraries |
---|---|
Frameworks | TensorFlow, Keras, Darknet (YOLOv4) |
Computer Vision | OpenCV, PIL |
Data Processing | NumPy, Pandas, Matplotlib |
Environment | Google Colab, Kaggle API |
- Clone the repository:
git clone https://github.com/mariam-khediri/Facial-Sentiment-Analysis-using-CNN.git cd facial-sentiment-analysis
- 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
- Download pretrained models:
python emotion_detection.py --mode=camera
Output:
- Processes webcam feed โ detects faces โ predicts emotions (
).
- Supports image input:
--image=test.jpg
.
python facial_recognition.py --dataset=lfw --epochs=120
Output:
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).
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 (
vs
).
- Data Augmentation: Improve test accuracy with transformations (rotation, scaling).
- Transformer Models: Experiment with Vision Transformers (ViT).
- API Deployment: Flask/Django backend for SaaS integration.
- Professional Supervisor: Mr. Bassem Hmissa (LEONI).
- Dataset Providers: Kaggle (FER-2013, LFW).
- Institutional Support: Sfax University, Tunisia.
MIT ยฉ Mariem Khedhiri