项目作者: manhminno

项目描述 :
Face recognition - realtime recognition by tf2
高级语言: Python
项目地址: git://github.com/manhminno/Face-Recognition.git
创建时间: 2020-12-15T15:28:41Z
项目社区:https://github.com/manhminno/Face-Recognition

开源协议:

下载


Face Recognition - Realtime Recognition

Table of Contents

1. Introduction

2. Requirement

3. Usage

4. Reference



1. Introduction

  • Face recognition is a technology capable of matching a human face from a digital image or a video frame against a database of faces, typically employed to authenticate users through ID verification services, works by pinpointing and measuring facial features from a given image.
  • Recognize and manipulate faces with Python and its support libraries.
    The project uses MTCNN for detecting faces, then applies a simple alignment for each detected face and feeds those aligned faces into embeddings model (Facenet).
    Finally, a softmax classifier and cosine similarity method was put on top of embedded vectors for classification task.

2. Requirement

  • Tensorflow-gpu (2.1.0)
  • Python 3.7+
  • Keras 2.2.4
  • OpenCV-python (4.4.0)
  • Pip or anaconda

    Install MTCNN:

    1. pip install mtcnn (for pip)
    2. conda install -c conda-forge mtcnn (for conda)

3. Usage

Crawl data:

  1. python src/save_data.py --name (name of save_dir)

Make sure your computer has a webcam

Preprocessing:

  • Train embedding model with your dataset, you need to organize dataset as follows:
    Each person needs 4-5 raw photos with many different angle shooting: front, left, right, …
    1. Face-Recognition
    2. └───data/
    3. └───person1/
    4. | └───person1_1.jpg
    5. | person1_2.jpg
    6. | .....
    7. └───person2/
    8. | └───person2_1.jpg
    9. | person2_2.jpg
    10. | .....
    11. └───personN/
    12. └───personN_1.jpg
    13. personN_2.jpg
    14. .....

    Augment data:

  • After having the raw image files, run augment_data.py to augment more images, each person after running will have 100 different images. Augments: rotation_range = 15, brightness_range=[0.4,1.5], horizontal_flip
    1. python augment_data.py

    Train embedding model:

    1. python train_embs.py
    After embedding, embedded file will be saved to output / train_embs.pickle

    Train softmax model:

    1. python train_classify.py
    The number of classes i’m setting here is 37 classes, so change the number of classes that match your dataset

    Enjoy result:

    1. <img alt="Qries" src="https://github.com/manhminno/Face-Recognition/blob/master/output/1.jpg">

Label is name of saved-dir - box is green, unknown will don’t have label - box is red. Here label is id of person.

  • For image recognition:
    1. python image_recognition.py --path (path to image) --facedetect (use MTCNN to detect face before recognition - yes/no)

    Output will be saved to output/(name_of_img.jpg)

  • For video recognition:
    1. python video_recognition.py --path (path to video) --facemodel (path of facenet weights) --classifymodel (path of classify model weight) --embspath (path of embed dir)
  • For stream recognition:
    1. python stream_recognition.py

    Make sure your computer has a webcam, here i’m setting webcam 0

4. Reference