Detect facial landmarks from Python using the world's most accurate face alignment network, capable of detecting points in both 2D and 3D coordinates.
Build using FAN's state-of-the-art deep learning based face alignment method. For detecting faces the library makes use of dlib library.
Note: The lua version is available here.
For numerical evaluations it is highly recommended to use the lua version which uses indentical models with the ones evaluated in the paper. More models will be added soon.
New retrained models will be posted at the end of november
import face_alignment
from skimage import io
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, enable_cuda=True, flip_input=False)
input = io.imread('../test/assets/aflw-test.jpg')
preds = fa.get_landmarks(input)
import face_alignment
from skimage import io
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._3D, enable_cuda=True, flip_input=False)
input = io.imread('../test/assets/aflw-test.jpg')
preds = fa.get_landmarks(input)
import face_alignment
from skimage import io
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, enable_cuda=False, flip_input=False)
input = io.imread('../test/assets/aflw-test.jpg')
preds = fa.detect_faces(input)
import face_alignment
from skimage import io
fa = face_alignment.FaceAlignment(face_alignment.LandmarksType._2D, enable_cuda=False, flip_input=False)
preds = fa.process_folder('../test/assets/', all_faces=True)
Please also see the examples
folder
- Python 3.5+ or Python 2.7 (it may work with other versions too)
- Linux or macOS (windows may work once pytorch gets supported)
- pytorch (>=0.4)
While not required, for optimal performance(especially for the detector) it is highly recommended to run the code using a CUDA enabled GPU.
Conda builds are coming soon!
Install pytorch and pytorch dependencies. Instructions taken from pytorch readme. For a more updated version check the framework github page.
On Linux
export CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" # [anaconda root directory]
# Install basic dependencies
conda install numpy pyyaml mkl setuptools cmake gcc cffi
# Add LAPACK support for the GPU
conda install -c soumith magma-cuda80 # or magma-cuda75 if CUDA 7.5