This project detects human emotions in real time using your webcam. It uses a Convolutional Neural Network (CNN) trained on the FER2013 dataset. Faces are detected using OpenCV with Haar cascades, and an appropriate emoji is overlaid on the image based on the recognized emotion.
Required libraries:
pip install torch torchvision opencv-python pandas numpy pillow
You'll also need the kaggle CLI to download the dataset:
pip install kaggle
Save your Kaggle API key in ~/.kaggle/kaggle.json or configure environment variables properly.
├── datasets/
│ ├── fer2013.csv
│ └── facialexpressionrecognition.zip
├── emojis/
│ ├── happy_emoji.png
│ ├── sad_emoji.png
│ └── ... (other emotions)
├── model/
│ └── saved_model.pth
├── main.py
├── README.md
The model recognizes the following emotions:
😠 Angry 🤢 Disgust 😱 Fear 😄 Happy 😐 Neutral 😢 Sad 😲 Surprise
Make sure the webcam works.
Run the script with python main.py
If the model is not found, training will start automatically.
The app will open a camera window showing detected faces with overlaid emojis.
A custom CNN trained on FER2013 with:
Convolutional + BatchNorm + LeakyReLU + MaxPooling layers
Dropout and Fully Connected layers
Trained using Adam optimizer and CrossEntropyLoss
Check your webcam and OpenCV installation if the app doesn’t start.
Make sure you have the correct version of PyTorch for your system.
Developed by a student ML developer.
This project is licensed under the MIT License.
