This project detects human emotions from facial expressions using a Convolutional Neural Network (CNN) model. The project uses the FER-2013 dataset for training and testing and includes a real-time emotion detection system using a webcam.
- Installation
- Dataset
- Data Preparation
- Training the Model
- Real-Time Emotion Detection
- Directory Structure
- Acknowledgements
-
Clone the repository:
git clone https://github.com/NoealRajeev/emotion-detection.git cd emotion-detection -
Create and activate a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
The project uses the FER-2013 dataset. You can download it from Kaggle. After downloading, place the dataset in the data/ directory following the structure described in the Directory Structure section.
The data preparation script preprocesses the dataset by resizing the images and normalizing the pixel values. Run the script to prepare the data:
python src/data_preparation.pyThis will generate train_images.npy, train_labels.npy, test_images.npy, and test_labels.npy files in the data/ directory.
To train the CNN model, run the training script:
python src/train_model.pyThe trained model will be saved in the models/ directory as emotion_detection_model.h5.
To run the real-time emotion detection using your webcam, execute the following script:
python src/real_time_detection.pyThis will open a window showing the webcam feed with the predicted emotion displayed.
emotion-detection/
├── data/
│ ├── test/
│ │ ├── angry/
│ │ ├── disgust/
│ │ ├── fear/
│ │ ├── happy/
│ │ ├── neutral/
│ │ ├── sad/
│ │ ├── surprise/
│ ├── train/
│ │ ├── angry/
│ │ ├── disgust/
│ │ ├── fear/
│ │ ├── happy/
│ │ ├── neutral/
│ │ ├── sad/
│ │ ├── surprise/
│ ├── train_images.npy
│ ├── train_labels.npy
│ ├── test_images.npy
│ ├── test_labels.npy
├── models/
│ └── emotion_detection_model.h5
├── notebooks/
├── src/
│ ├── __init__.py
│ ├── data_preparation.py
│ ├── train_model.py
│ └── real_time_detection.py
├── .gitignore
├── README.md
└── requirements.txtFeel free to fork this project, raise issues, or contribute to it. Happy coding!
- Kaggle for providing the FER-2013 dataset.
- TensorFlow for the machine learning framework.
- Installation: Instructions to clone the repository, set up a virtual environment, and install dependencies.
- Dataset: Information on where to download the dataset and how to place it in the directory.
- Data Preparation: Instructions to run the data preparation script.
- Training the Model: Steps to train the CNN model.
- Real-Time Emotion Detection: Steps to run the real-time emotion detection script.
- Directory Structure: Detailed layout of the project directory.
- Acknowledgements: Credits to sources and tools used in the project.