This is a CNN based emotion detector.
It can detect 6 facial expressions:
- Angry
- Disgust
- Fear
- Happy
- Sad
- Surprise
- Neutral
The CNN has been trained on the FER2013 dataset available on Kaggle.
To build the dataset, run buildDataset.py
to build the dataset. Provide the path to the dataset inside the file.
python buildDataset.py
To train the CNN, use the trainRecognizer.py
class. You can train the model using checkpoints. When the model seems to be overfitting or underfitting, pause the training, adjust the script and resume training from the same checkpoint.
python trainRecognizer.py --checkpoints checkpoints
To resume from the epoch where the training wa stopped:
python trainRecognizer.py --checkpoints checkpoints --model checkpoints/epoch_40.hdf5 --start-epoch 40
I used the model obtained at epoch 75 for all purposes. To test the model run testRecognizer.py
.
python test_recognizer.py --model checkpoints/epoch_75.hdf5
To detect emotions in a real time feed from the camera, use the emotionDetector.py
script. In order to detect multiple faces use the emotionDetectorMultipleFaces.py
script.
python emotionDetector.py --cascade haarcascade_frontalface_default.xml --model checkpoints/epoch_75.hdf5
python emotionDetectorMultipleFaces.py --cascade haarcascade_frontalface_default.xml --model checkpoints/epoch_75.hdf5
Results:
PS: I think I am a robot and therefore the only emotion I have is neutral and it's the only screenshot I was able to upload.