rileykwok / Face-Recognition-Model-with-Gender-Age-and-Emotions-Estimations

Capstone Project by Bertrand Lee and Riley Kwok
90 stars 37 forks source link

Face-Recognition-Model-with-Gender-Age-and-Emotions-Estimations

Capstone Project by Bertrand Lee and Riley Kwok

Table of Contents

About

We created a prototype face recognition system based on three pre-trained CNN models that is able to identify faces and predict their gender, age and emotions in an image or video.

The prototype is designed to be implemented in the retail industry for different applications:

Technical System Architecture

Stages Face Detection Face Alignment Face Feature
Extraction
Face Classification
ML Models OpenFace.nn4
(Identity)
WideResNet
(Age, Gender)
mini_XCEPTION
(Emotions)
SVM Classifier
Libraries Dlib OpenCV Keras
TensorFlow
Scikit Learn
Language Python Python Python Python

Results

[Left] System detected new customer face at promotion booth and shows the estimated gender, age and emotion.
[Right] Video shows how a known customer is being identified and how his emotion is being tracked.

We have trained the system on some celebrities and some of our friends, we noted that in some cases that the 2 face vectors of 2 different people were even located closer then each other (euclidean distance) than two photos of one person. From what we tested, using 5+ photos per person with clean, clear, front facing faces would produce better results for identity estimates.

The SVM classifier is also prefered over KNN classifier as they produce slightly better estimation. It also provides a confidence score per estimate which allows us to set a threshold to categorize known or new faces. The confidence score threshold we experimented that works best is 0.3.

References

Face Detection: DLib
Face Alignment: OpenCV:
Face Recognition Models:
OpenFace/ Facenet nn4.small model
Oarriaga/ mini_XCEPTION Emotion Model
WideResNet Age_Gender_Model
Face Recogition Explained and Codes: Karasserm
Age/Gender Prediction Explained and Codes: Chengwei

Installations

To run the model, please install the required python packages using

pip install -r requirements.txt

To run real-time demo:

python face_reco_demo.py

To run face recognition model:

python face_reco_base.py
python face_reco_image.py
python face_reco_video.py

Image:

face = FaceImage()
display_labeled_image(face, "sample/sample01.jpg")

Video to video:

labeled_video = FaceVideo("sample/sample02.mp4")
labeled_video.create_mp4_video("sample02vid.mp4")

Video to GIF:

labeled_video = FaceVideo("sample/sample02.mp4")
labeled_video.create_animated_gif("sample02gif.gif")

To train new faces for face identification:
Import photos to faces/name_of_person/001.jpg and run the codes again.

To visualise face vectors of trained faces (using t-SNE dimension reduction):

face_recognizer.visualize_dataset()