Emotion recognition (Angry, Disgust, Fear, Happy, Sad, Surprise, Neutral) using CNN with Python 3.x
EmotionRecognition in action.
-
Move to the project directory.
-
Make sure you have all the libraries required by running the following command on your cmd/terminal.
pip install -r requirements.txt
-
The dataset to train and test our CNN model will be extracted from a CSV file with the following description:
-
The data consists of 48x48 pixel grayscale images of faces.
-
The faces have been automatically registered so that the face is more or less centered and occupies about the same amount of space in each image.
-
The task is to categorize each face based on the emotion shown in the facial expression into one of seven categories (0=Angry, 1=Disgust, 2=Fear, 3=Happy, 4=Sad, 5=Surprise, 6=Neutral).
-
emotionData.csv contains two columns, "emotion" and "pixels".
-
The "emotion" column contains a numeric code ranging from 0 to 6, inclusive, for the emotion that is present in the image.
-
The "pixels" column contains a string surrounded in quotes for each image.
-
The contents of this string a space-separated pixel values in row-major order.
- emotionData.csv - Download dataset file
-
-
This program uses your phone's camera as its video source. To make that work you'll have to download the IP Webcam application from the Google Play Store. After you have the application downloaded scroll to the bottom and press Start Server which begins to stream the video. Once the video starts to stream you will see the IPv4 address displayed on the screen of the mobile application. Copy that IP address and go to main.py -> EmotionRecognition class -> init and set the URL to the IP Address mentioned on IP Webcam application. Note: Your PC and mobile should be connected to the same wi-fi network for this to work.
- IP Webcam - Download IP Webcam
-
Finally, run the main.py file to start execution.
Note: Make sure the emotionData.csv dataset file is in the project directory and also make sure the video is streaming before running main.py [4]
python main.py
- Keras - The Python Deep Learning library.
- Pandas - Python Data Analysis Library.
- NumPy - The fundamental package for scientific computing with Python.
- OpenCV - A library of programming functions mainly aimed at real-time computer vision.
- PIL - Python Imaging Library is a free library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats.
- Crayons - TextUI colors for Python.