Facial Emotion Detection CNN
Model Details
Model Name: Facial Emotion Detection CNN
Model Type: Convolutional Neural Network (CNN)
Framework: TensorFlow / Keras
Number of Parameters: ~4.47 Million
Description:
This is a custom-built Convolutional Neural Network designed to classify human facial expressions into 6 distinct emotion categories from static images. The model was fine-tuned on an augmented version of the well-known FER-2013 dataset. It utilizes aggressive dropout and batch normalization to ensure robust generalization.
Emotions Detected:
- π Angry
- π¨ Fear
- π Happy
- π Neutral
- π’ Sad
- π² Surprise
(Note: The 'Disgust' class from the original FER-2013 dataset was dropped due to extreme class imbalance and low sample count.)
Model Architecture
- Input: 48x48 Grayscale Images
(48, 48, 1) - Convolutional Blocks: 4 Conv2D blocks with increasing filter sizes (64, 128, 512, 512) and ReLU activation.
- Pooling: MaxPooling2D applied after each convolutional block.
- Regularization: Batch Normalization applied after every Conv2D and Dense layer. Dropout layers (0.25 to 0.5) applied heavily to prevent overfitting.
- Classifier: Flatten layer followed by Dense layers (256, 512 nodes), ending in a Softmax output layer with 6 nodes.
Training Data
The model was trained on the FER-2013 dataset.
- Preprocessing: Images resized to 48x48 pixels and normalized to
[0.0, 1.0]. - Training Samples: 28,272 images.
- Validation/Test Samples: 7,068 images.
- Augmentation Applied: 15-degree rotation, 10% width/height shifts, 10% zoom, and horizontal flipping.
Evaluation Results
The model was evaluated on a 20% unseen stratified test set from the FER-2013 dataset.
- Overall Test Accuracy: 77.05%
- Correct Predictions: 5,446 / 7,068
How to Use
You can load and use this model directly with TensorFlow/Keras for predicting emotions on preprocessed 48x48 grayscale images.
import cv2
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import load_model
# 1. Load the model
model = load_model('emotion_model_finetuned_final.keras')
# 2. Define Emotion Labels
EMOTION_LABELS = {0: 'Angry', 1: 'Fear', 2: 'Happy', 3: 'Sad', 4: 'Surprise', 5: 'Neutral'}
# 3. Preprocess your image
# Image must be a 48x48 grayscale numpy array
def predict_emotion(image_path):
# Read as grayscale
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
# Resize to 48x48
img = cv2.resize(img, (48, 48))
# Normalize pixel values
img = img.astype('float32') / 255.0
# Expand dimensions to match model input shape (1, 48, 48, 1)
img = np.expand_dims(img, axis=0)
img = np.expand_dims(img, axis=-1)
# Predict
predictions = model.predict(img)
max_index = np.argmax(predictions[0])
confidence = np.max(predictions[0])
emotion = EMOTION_LABELS[max_index]
print(f"Predicted Emotion: {emotion} (Confidence: {confidence*100:.2f}%)")
return emotion
# Run prediction
# predict_emotion('path_to_your_face_image.jpg')
Limitations and Bias
- Lighting and Angles: The model performs best on well-lit, front-facing faces. Extreme profiles, occlusions (like thick glasses or face masks), or intense shadows will degrade confidence.
- Grayscale Restriction: The model strips color data. While this saves computational power, it may miss subtle physiological cues (like blushing) associated with real human emotion.
- Dataset Bias: Inherits any demographic, ethnic, or age-related biases present in the base FER-2013 dataset. Performance may vary across different demographic groups.
Team Members (Inflators)
- DTPD Wickramasinghe (Group Leader)
- DVTR Vitharana
- RSR Ranathunga
- DDSS Kumasaru
- SHD Mihidumpita
- Downloads last month
- 35