Skip to content

Face detection and recognition in tensorflow2.0+. Add any persons face you want to recognize in this framework !

Notifications You must be signed in to change notification settings

StanislasBertrand/UniversalFaceRecog-TF2

Repository files navigation

Tensorflow2 face recognition framework

Face recognition framework with 80 pretrained celebrities to recognize.
Easily add any person to the database !

example output : testing on a leaders_photo
Check out more examples at the bottom of the page !

INSTALLATION

run

python setup.py install

If you dont have a GPU, change the line tensoflow-gpu==2.0.1 to tensorflow==2.0.1 from the setup.py file.

USAGE

First, download the pretrained models and list of available celebrities from DropBox, and place the models in the ./models folder

Run :

python recognition.py --sample_img="./sample-images/leaders.jpg" --save_destination="./sample-results/leaders_output.jpg"

Python usage :

import cv2
from retinaface.FaceDetector import FaceDetector
from retinaface.alignment import extract_aligned_faces
from recognition.FaceRecognizer import FaceRecognizer

detector = FaceDetector("./models/retinafaceweights.npy", False, 0.4)
recognizer = FaceRecognizer("./models/index.nms", "./models/celebrities_mapping.json", "./models/faceEmbeddings.npy")

img = cv2.imread("./sample-images/leaders.jpg")
faces, landmarks = detector.detect(img, 0.9)
aligned_faces = extract_aligned_faces(img, landmarks)
aligned_face = aligned_faces[0]
found_person = recognizer.run(aligned_face, 0.6)

ADD YOUR OWN CELEBRITIES

In order to add more people to the recognition database, follow the tutorial

STRUCTURE

retinaface
This folder contains the code for face detection and alignment. It is based on this original paper, and this implementation.

recognition
This folder contains the code that takes as input a face and recognizes a person, in two steps:

  • Deep learning based face embedding extraction. This neural network take as input a face, returns a feature vector of size 512.
  • nearest neighbor search to find a matching embedding of a person in our database. Takes a input an embedding vector, and tries to look for similar embedding vectors in our people database. If a vector in our database is close enough, then we have found that person.

train
This folder contains scripts to add any person to the face recognition database

EXAMPLE OUTPUTS

testing on heat testing on emmas testing on tarantino testing on pulp testing on batman

TODO

  • add alignment to mtcnn
  • convert embedding extractor to tf2
  • convert RetinaFace to tf2 for better face detection
  • add nmslib knn search for face rec
  • add test code for face detection + recognition
  • create first index of people face embeddings
  • automate pipeline of adding new persons to recognition database
  • Add more people to the original pretrained celebrities dataset
  • Increase accuracy on low res images by augmenting train images
  • Finish airflow pipeline for database creation

ACKONWLEDGEMENTS

Most of this work is based on the work of Insightface and MMdnn If you use this repo, please reference the original face detection work :

@inproceedings{Deng2020CVPR,
title = {RetinaFace: Single-Shot Multi-Level Face Localisation in the Wild},
author = {Deng, Jiankang and Guo, Jia and Ververas, Evangelos and Kotsia, Irene and Zafeiriou, Stefanos},
booktitle = {CVPR},
year = {2020}
}

About

Face detection and recognition in tensorflow2.0+. Add any persons face you want to recognize in this framework !

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages