Emotion Detection
This project is a real-time emotion detection application that uses a deep learning model to identify emotions from human faces in images. The application is built with Python and utilizes PyTorch for the model, OpenCV for image processing, and Gradio for the user interface.
Features
- Face Detection: Automatically detects faces in an uploaded image.
- Emotion Recognition: Classifies the emotion of each detected face into one of seven categories:
- Angry
- Disgust
- Fear
- Happy
- Neutral
- Sad
- Surprise
- Web Interface: A simple and intuitive web interface powered by Gradio to upload images and view the results.
Project Structure
βββ app.py # Main application file with the Gradio interface
βββ requirements.txt # Project dependencies
βββ checkpoints/ # Contains pre-trained model weights
β βββ emotion_recognition/
β βββ face_detect/
βββ dataset/ # Image data for training and testing
β βββ emotions/
βββ src/ # Source code for the project
βββ dataset.py # Handles data loading
βββ emotion_recognition_model.py # Emotion recognition model architecture
βββ face_detect_model.py # Face detection model architecture
βββ pipeline.py # Chains face detection and emotion recognition
βββ train.py # Script for training the models
Installation
Clone the repository:
git clone https://huggingface.co/RashaadAhmad/Emotion-Detection cd emotion-detectionCreate and activate a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`Install the dependencies:
pip install -r requirements.txt
Usage
Click Here to try it out.
To start the application and its web interface, run the following command:
python app.py
This will launch a local web server. Open the provided URL in your browser to access the application. You can then upload an image to see the emotion detection in action.
Training
The model has been pre-trained, and the weights are available in the checkpoints directory. However, if you wish to retrain the model on a different dataset, you can use the train.py script:
python src/train.py
Make sure your dataset is structured correctly in the dataset directory.