FaceOff is a toy face recognition application built with VGG-Face, OpenCV, and Tensorflow/Keras.
FaceOff requires Python 3.x but not greater than 3.6. This is important because Tensorflow doesn't support Python 3.7 yet.
Having clonned this repo, it is recommended that you bootstrap a separate Python virtual environment to setup the codebase. To create a virtual environment, you can either use Anaconda or the default venv module that ships with Python. Follow the instructions below to setup using either Anaconda, or venv.
- Download and install Anaconda from https://www.anaconda.com/
- Run "conda env create -f environment.yml"
- Run "conda activate faceoff"
- CD into the base directory of this repository on your machine
- Run "python3 -v venv env"
- Run "source env/bin/activate"
- Run "pip install -r requirements.txt"
Because this application depends on the VGG-Face model to encode important facial features, you'll need to download the weights file. Click here to download. It's a big file (about 500MB and named vgg_face_weights.h5) so be patient. After downloading, copy the weights file into the root of the codebase on your machine.
In the root of the codebase, fun the following command:*
python3 main.py --weights vgg_face_weights.h5 --distance 0.2 The flag --weights specifies the path to the pre-trained VGG-Face weights file and --distance specifies the similarity threshold used to determine matched faces. The value for --distance MUST ALWAYS be a number between 0 and 1 since the application uses the Cosine Similarity Measure.
You can see a video of it in action on my AI Weekend Hacks playlist
- OpenCV's HaarsCascade classifier is used to detect faces from the camera feed.
- Rectangles are drawn where the classifier sees faces
- Pressing the 'r' key will let your register a new user by entering his/her fullname in the terninal
- Whiles registering a new user, make sure he/she is the only face seen by the camera
- VGG-Face is used to encode facial features into 2622-dimensional vectors and store in /faces as [username].npy
- When multiple faces are identified by the classifier, matching is done by comparing cosine distance of all known faces.
- When matches are found, their names are shown. Otherwise, "unknown user" is shown.
You're definitely welcome to submit pull requests for improvements. Below are some of the immediate improvements that can be made:
- Use OpenCV's DNN classifer instead of HaarsCascade classifier.
- Use DLib to detect faces from varied angles instead of HaarsCascade which doesn't really work well.
- Improve performance
- Improve documentation.