Skip to content

Face detection and recognition + liveness detection and spoofing attack recognition using onnxruntime. Includes an easy-to-use Flask API and Dockerfile.

Notifications You must be signed in to change notification settings

jijibao011/face-recognition-liveness

 
 

Repository files navigation

face-recognition-liveness

Face liveness detection and indentity recognition using fast and accurate convolutional neural networks is implemented in Pytorch. Also a Flask API and ready-to-use Dockerfile can be found in this repository.

This project uses Mediapipe for face detection and the face recognition model is borrowed from facenet-pytorch .The liveness detection model came from Deep Pixel-wise Binary Supervision for Face Presentation Attack Detection paper and, pre-trained models are published by authors.

face recognition and liveness

Getting Started

Download .onnx models and put them in data/checkpoints folder.

Note: If you have an internet connection, models will be downloaded automatically.

Simple Usage

Run the following command to check liveness (and test are you Ryan Reynolds or not!)

$ python webcam_test.py

Note: Liveness score is between 0 and 1 and, in average, it is enough be greater than ~ 0.03 to be considered as a live image.

Create Facebank CSV

In the first step you need a facebank. So put some images (jpg, jpeg, png) in a folder and create facebank csv file using create_facebank.py script:

$ python3 create_facebank.py --images ./data/images \
--checkpoint ./data/checkpoints/InceptionResnetV1_vggface2.onnx \
--output ./data/test.csv

--images: the path to the images folder

--checkpoint: the path to the resnet vggface2 onnx checkpoint

--output: the path to the output csv file

Run Docker

Now you can start the deployment process. Variables (models and facebank names) can be changed in app/.env file:

DATA_FOLDER=data
RESNET=InceptionResnetV1_vggface2.onnx
DEEPPIX=OULU_Protocol_2_model_0_0.onnx
FACEBANK=test.csv

First build the docker image:

$ sudo docker build --tag face-demo .

Now run the image as a container:

$ sudo docker run -p 5000:5000 face-demo python3 -m flask run --host=0.0.0.0 --port=5000

Test

Finally we can test our app using a python client. So for testing just run this:

# face-recognition-liveness/
$ cd ./app
$ python3 client.py --image ../data/images/reynolds_001.png --host localhost --port 5000 --service main 

About

Face detection and recognition + liveness detection and spoofing attack recognition using onnxruntime. Includes an easy-to-use Flask API and Dockerfile.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 97.5%
  • Dockerfile 1.8%
  • Shell 0.7%