Skip to content

A lightweight python implementation of face alignment with MTCNN landmarks using tensorflow-lite runtime

License

Notifications You must be signed in to change notification settings

Martlgap/face-alignment-mtcnn

Folders and files

NameName
Last commit message
Last commit date
Mar 18, 2024
Jun 17, 2021
Aug 1, 2021
Sep 12, 2024
May 5, 2021
May 5, 2021
May 5, 2021
Mar 18, 2024
May 5, 2021
Jun 17, 2021
Sep 12, 2024
Feb 8, 2023
Aug 1, 2021

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.