Skip to content

paoloripamonti/face-recognition

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Recognition

Simple library to recognize faces from given images

Face Recognition pipeline

Below the pipeline for face recognition:

  • Face Detection: the MTCNN algorithm is used to do face detection
  • Face Alignement Align face by eyes line
  • Face Encoding Extract encoding from face using FaceNet
  • Face Classification Classify face via eculidean distrances between face encodings

How to install

pip install git+https://github.com/paoloripamonti/face-recognition

How to train custom model

Initialize model

from face_recognition import FaceRecognition

fr = FaceRecognition()

Train model with pandas DataFrame:

fr = FaceRecognition()

fr.fit_from_dataframe(df)

where 'df' is pandas DataFrame with column person (person name) and column path (image path)

Train model with folder:

fr = FaceRecognition()

fr.fit('/path/root/')

the root folder must have the following structure:

root\
    Person_1\
        image.jpg
        ...
        image.jpg
    Person_2\
        image.jpg
        ...
        image.jpg
    ...
        

Save and load model

you can save and load model as pickle file.

fr.save('model.pkl')
fr = FaceRecognition()

fr.load('model.pkl')

Predict image

fr.predict('/path/image.jpg')

Recognize faces from given image. The output is a JSON with folling structure:

{
  "frame": "image data", # base64 image with bounding boxes
  "elapsed_time": time, # elapsed time in seconds
  "predictions": [
      {
        "person": "Person", # person name
        "confidence": float, # prediction confidence
        "box": (x1, y1, x2, y2) # face bounding box
      }
  ]
}

Example

For more details you can see: https://www.kaggle.com/paoloripamonti/face-recogniton