A face recognition pipeline implementation to do face detection and face identification in Java.
Integrated pretrained third party models for face detection and embedding calculation using DJL.
Face identification implemented using cosine distance between calculated embeddings and target face.
Commands to build the project:
git lfs install
git clone https://github.com/jmformenti/face-recognition-java.git
cd face-recognition-java
mvn package
A fatjar face-recognition-java-${VERSION}.jar
will be placed in cli/target
dir.
-
Prepare data, one root directory with one subdirectory with images of each person (for example, see
src/test/resources/images/train
). -
Generate embeddings file.
java -jar cli/target/face-recognition-java-${VERSION}.jar embed -p /path/to/root/images -e embeddings.dat
-
Recognize faces in one image.
java -jar cli/target/face-recognition-java-${VERSION}.jar predict -e embeddings.dat -p /path/to/image
As a result a new image with detected faces will be created in the same path with suffix
_result.jpg
.
mvn clean deploy -P release
Two models are used:
Model | Type | References |
---|---|---|
PaddlePaddle (DJL,flavor=server) | Face detection | https://docs.djl.ai/jupyter/paddlepaddle/face_mask_detection_paddlepaddle.html https://paddledetection.readthedocs.io/featured_model/FACE_DETECTION_en.html |
20180402-114759 converted to TorchScript | Face embeddings | https://github.com/timesler/facenet-pytorch |
Tasks to improve the performance:
- Apply face alignment before embeddings calculation.
- Use some classifier to pass from an embedding to the person label.
- Deep Java Library
- Q. Cao, L. Shen, W. Xie, O. M. Parkhi, A. Zisserman. VGGFace2: A dataset for recognising face across pose and age, International Conference on Automatic Face and Gesture Recognition, 2018.
- Jason Brownlee PhD, Machine Learning Mastery, How to Perform Face Recognition With VGGFace2 in Keras
- 5 Celebrity Faces Dataset used for testing.