项目作者: paoloripamonti

项目描述 :
Face Recognition
高级语言: Python
项目地址: git://github.com/paoloripamonti/face-recognition.git
创建时间: 2019-09-26T08:39:11Z
项目社区:https://github.com/paoloripamonti/face-recognition

开源协议:

下载


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

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

How to train custom model

Initialize model

  1. from face_recognition import FaceRecognition
  2. fr = FaceRecognition()

Train model with pandas DataFrame:

  1. fr = FaceRecognition()
  2. fr.fit_from_dataframe(df)

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

Train model with folder:

  1. fr = FaceRecognition()
  2. fr.fit('/path/root/')

the root folder must have the following structure:

  1. root\
  2. Person_1\
  3. image.jpg
  4. ...
  5. image.jpg
  6. Person_2\
  7. image.jpg
  8. ...
  9. image.jpg
  10. ...

Save and load model

you can save and load model as pickle file.

  1. fr.save('model.pkl')
  1. fr = FaceRecognition()
  2. fr.load('model.pkl')

Predict image

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

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

  1. {
  2. "frame": "image data", # base64 image with bounding boxes
  3. "elapsed_time": time, # elapsed time in seconds
  4. "predictions": [
  5. {
  6. "person": "Person", # person name
  7. "confidence": float, # prediction confidence
  8. "box": (x1, y1, x2, y2) # face bounding box
  9. }
  10. ]
  11. }

Example

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