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!
- very simple and lightweight face detection and face alignment based on MTCNN
- no GPU needed
- multi platform support (Windows, MacOS, Ubuntu)
- Warnings if image will be heavily distorted during alignment process
- Python 3.9
- TensorflowLite-Runtime 2.5.0
- Tested on: Ubuntu 20.04, Windows 10, MacOS 11.3
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
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
- 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>)
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
- 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.