1. 程式人生 > >Face Recognition README

Face Recognition README

Face Recognition

A light weight face recognition implementation using a pre-trained facenet model. Most of the code is taken from David Sandberg’s facenet repository.


Steps to follow:

  1. Create a dataset of faces for each person and arrange them in below order
root folder  
│
└───Person 1
│   │───IMG1
│   │───IMG2
│   │   ....
└───Person 2
|   │───IMG1
|   │───IMG2
|   |   ....
  1. Create embeddings of this dataset by running python script/create_embeddings.py --input_dir = $(/path/to/your/image/dataset) a pickle file embeddings.pickle will be created in your folder
  2. script/face_recognition.py contains most functionalities for face recognition task. Input a face image of a person in the dataset, face_recognition.py
    calculates the distances between embedding of input image and embeddings in the dataset, and return the one with minimum distance
    i.e.
_, face, bboxes = align_face(image_path='path/to/image',
							 image_size = 160,
							 margin=44,
							 gpu_memory_fraction=1.0							 

emb = create_embeddings(
face, model_dir='/path/to/facenet/model') embs = load_embeddings(emb_filepath='path/to/embedding/lists') result, _ = identify_person(emb, embs)
align_face

detect face in an image and returns cropped image and resize it to 160x160
Args:

  • image_path: path to image
  • image_size: image size to be aligned
  • margin: margin for the crop around the bounding box (height, width) in pixels.
  • gpu_memory_fraction: percentage of gpu memory to be allocated

Returns:

  • True if face is detected, false otherwise
  • aligned face
  • bounding box