Read more about this project and learn about the theory and thinking process behind it in my blog on Medium.
This project has four major steps:
- Create the dataset
- Prep the dataset using MTCNN
- Using a FaceNet model to generate face emeddings for each training example
- Passing our data through a custom SVM to make predictions If you want to detect the faces in a videostream in real-time, then you should take a look at this file.
Your dataset directory should have two folders, a train and a validation. In those directories you should have a subdirectory for each person you want to detect. Take a look at the dataset I have included in this repo for reference. This dataset is the 5 celebrity faces dataset from Kaggle. Note, I did not train this model on this dataset. I used a custom dataset with images of my firends which I have not included here for privacy reasons.
Next, you should run friends_dataprep.py. I developed this script to run MTCNN on every image in the dataset being used. It creates a tensor (numpy array) containing the face pixels in each image and save it as an .npz file.
Use facenet.py to generate face embeddings and make a new .npz file of the new np array
Train an SVMclassifier.py using the numpy array to classify the faces.
Take a look at this script. I used Haarcascade to detect faces from each frame, you can however use MTCNN again. I pass the face detected through our models to make a prediction.