Skip to content

Martlgap/face-alignment-mtcnn

Repository files navigation

face-alignment-mtcnn

Code style: black Contributors Last Commit License Downloads CI testing CI make_release

📘 Description

A very simple and lightweight pure python implementation of face-alignment with MTCNN landmark-extractor. The tool uses tensorflow-lite (CPU only) and supports several platforms.

Pull request are welcome!

⚡️ Features

  • very simple and lightweight face detection and face alignment based on MTCNN
  • no GPU needed
  • multi platform support (Windows, MacOS, Ubuntu)

✅ ToDos

  • Warnings if image will be heavily distorted during alignment process

🥣 Requirements

⚙️ How to install tflite-runtime

You can easily install tflite-runtime from https://google-coral.github.io/py-repo/ with the following line:

pip3 install tflite-runtime --find-links https://google-coral.github.io/py-repo/tflite-runtime

⚙️ How to install the face-alignment package

Simply install the package via pip from git:

pip3 install git+https://github.com/martlgap/face-alignment-mtcnn

or if you do not have git installed on your system, install it directly from the wheel:

pip3 install https://github.com/Martlgap/face-alignment-mtcnn/releases/latest/download/face_alignment_mtcnn-0.3-py3-none-any.whl

🏠 Basic Usage

  • Simply import the facealignment package
  • Instantiate the tools
  • Use the "align()" method to align a face from an arbitrary image
import facealignment

tools = facealignment.FaceAlignmentTools()
aligned_face = tools.align(<image>)

🚀 Run Example

Download repository and run it with Python 3.8:

python example.py

A cv2 window will pop up, showing you the alignment. Press any key, to go to the next cv2 window and finally close the window

🙏 Acknowledgement

  • Thanks to Iván de Paz Centeno for his implementation of MTCNN in Tensorflow 2. The MTCNN model weights are taken "as is" from his repository and were converted to tflite-models afterwards.