AI Face comparison using FaceNet, compare two photos and see if they are the same person.
pip install face-compare
Use compare_faces.py
to compare two images of people to see if they are the same person.
compare_faces.py --image-one /path/to/image_one.png --image-two /path/to/image_two.png
Optionally output the cropped image output to a directory (useful for inspecting input to AI model)
compare_faces.py --image-one /path/to/image_one.png --image-two /path/to/image_two.png -s /path/to/outputs/
- A cascade classifier is used to detect the face within the input images.
- The bounding box of this segmentation is then used to crop the images, and fed into the AI model.
- The FaceNet model then calculates the image embeddings for the two cropped images.
- Finally the second embedding is subtracted from the first, and the Euclidean norm of that vector is calculated.
- A threshold of 0.7 is used to determine whether they are the same person or not.
If you are trying to run the module without a suitable GPU, you may run into the following error message:
tensorflow.python.framework.errors_impl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU
To fix this issue with Intel CPU architecture, you can install the TensorFlow Intel Optimization package via
pip install intel-tensorflow
This module uses the AI model FaceNet, which can be found here, and the journal article here.