A real-time facial emotion recognition system that detects and classifies seven human emotions using deep learning and computer vision.
This application uses a Convolutional Neural Network (CNN) trained on facial expressions to detect and classify emotions in real-time through a webcam feed. The system can identify seven different emotions: anger, disgust, fear, happiness, neutrality, sadness, and surprise.
- Real-time emotion detection through webcam
- User-friendly GUI built with CustomTkinter
- Visual feedback with progress bars for each emotion probability
- Easy-to-use controls for starting/stopping detection
- Responsive design that works on various screen sizes
The model was trained using the Face Expression Recognition Dataset from Kaggle. This dataset contains approximately 35,000 grayscale images of faces displaying various emotions.
The dataset includes:
- 7 emotion categories (angry, disgust, fear, happy, neutral, sad, surprise)
- 48x48 pixel grayscale images
- Images already aligned and centered on the face
The CNN model architecture includes:
- Multiple convolutional layers with batch normalization
- Max pooling layers for feature extraction
- Dropout layers to prevent overfitting
- Dense layers for classification
- L2 regularization for better generalization
The trained model achieved 79% accuracy on the validation set, which is competitive with state-of-the-art models on this challenging dataset.
- Python 3.7+
- TensorFlow 2.x
- OpenCV
- CustomTkinter
- PIL (Pillow)
- NumPy
- Clone this repository:
git clone https://github.com/yourusername/emotion-detection.git
cd emotion-detection- Make sure you have a webcam connected to your system.
- Run the application:
python emotion_detector.py-
Click "Start Detection" to begin emotion recognition.
-
The application will display:
- Live webcam feed
- Currently detected emotion
- Probability bars for each emotion
-
Click "Stop Detection" to pause or "Quit" to exit the application.
If you want to train your own model:
-
Download the Face Expression Recognition Dataset from Kaggle.
-
Organize the dataset in the following structure:
carpetas/
├── train/
│ ├── angry/
│ ├── disgust/
│ ├── fear/
│ ├── happy/
│ ├── neutral/
│ ├── sad/
│ └── surprise/
└── test/
├── angry/
├── disgust/
├── fear/
├── happy/
├── neutral/
├── sad/
└── surprise/
- Run the training script:
python train_model.py- The trained model will be saved as
modelo_entrenado.keras.
- Face Expression Recognition Dataset by Jonathan Oheix
- TensorFlow team for the deep learning framework
- CustomTkinter for the modern UI components
If you have any questions or suggestions, please open an issue or contact carrillomauricio007@gmail.com.
