Skip to main content

Face recognition using TensorFlow

None

Project description

Facial Recognition and Alignment

What's this?

This repository contains a refactored implementation of David Sandberg's FaceNet and InsightFace for facial recognition. It also contains an implementation of MTCNN and Faceboxes for face cropping and alignment. What is in the refactor:

  • Made algorithms easily and efficiently usable with convenience classes.
  • Added much more efficient methods of batch processing face recognition and alignment
  • Added true face alignment (with affine transformation) to align face to bottom-center of image: code
  • Added proportional margin to alignment as per this issue
  • Ability to easily switch between insightface and facenet at inference time

More information on customizing and implementing new face detection algorithms can be found here.

Installation

To use in other projects, this implementation can be pip installed as follows:

pip install facenet_sandberg

To use locally:

  1. Clone repo
  2. cd to base directory with setup.py
  3. run:
pip install -e .

^(installs package in development mode)

Important Requirements

  1. Python 3.5
  2. Tensorflow==1.7
  3. Tensorlayer==1.7 The rest is specified in requirements.txt

Models

Links to pretrained models:

Datasets

Links to download training datasets (!big files!):

Image directory structure

This repo assumes images are in LFW format:

-/base_images_folder
  -/person_1
    -person_1_0001.jpg
    -person_1_0002.jpg
    -person_1_0003.jpg
  -/person_2
    -person_2_0001.jpg
    -person_2_0002.jpg
  ...

If your dataset is not like this you can use lfw.py to put your images into the right format like so (from facenet_sandberg/facenet_sandberg):

python lfw.py --image_directory PATH_TO_YOUR_BASE_IMAGE_DIRECTORY

Alignment

Alignment is done with a combination of Faceboxes and MTCNN. While Faceboxes is more accurate and works with more images than MTCNN, it does not return facial landmarks. Whichever algorithm returns more results is used.

Use the align_dataset.py script to align an entire image directory:

python align_dataset.py --input_dir PATH_TO_YOUR_BASE_IMAGE_DIRECTORY \
                        --output_dir PATH_TO_OUTPUT_ALIGNED_IMAGES \
                        --facenet_model_checkpoint PATH_TO_PRETRAINED_FACENET_MODEL \
                        --image_height DESIRED_IMAGE_HEIGHT \
                        --image_width DESIRED_IMAGE_WIDTH \
                        --margin DESIRED_PROPORTIONAL_MARGIN \
                        --scale_factor DESIRED_SCALE_FACTOR \
                        --steps_threshold DESIRED_STEPS \
                        --detect_multiple_faces \
                        --use_faceboxes \
                        --use_affine \
                        --num_processes NUM_PROCESSES_TO_USE
  • Default values for most arguments are provided here

Generate Pairs.txt

A pairs.txt file is used in training and testing. It follows this format. In order to generate your own pairs.txt run:

python align_dataset.py --image_dir PATH_TO_YOUR_BASE_IMAGE_DIRECTORY \
                        --pairs_file_name OUTPUT_NAME_OF_PAIRS_FILE \
                        --num_folds NUMBER_OF_FOLDS_FOR_CROSS_VALIDATION \
                        --num_matches_mismatches NUMBER_OF_MATCHES_AND_MISMATCHES

Copyright

MIT License from original repo https://github.com/davidsandberg/facenet/blob/master/LICENSE.md

Project details

None

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

facenet_sandberg-0.0.8.tar.gz (42.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page