face alignment
v1.4.0
使用世界上最準確的臉部對齊網路從 Python 偵測臉部標誌,能夠偵測 2D 和 3D 座標中的點。
使用 FAN 最先進的基於深度學習的人臉對齊方法進行構建。
import face_alignment
from skimage import io
fa = face_alignment . FaceAlignment ( face_alignment . LandmarksType . TWO_D , 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 . THREE_D , 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 . TWO_D , flip_input = False )
preds = fa . get_landmarks_from_directory ( '../test/assets/' )
預設情況下,該套件將使用 SFD 臉部偵測器。然而,使用者也可以使用 dlib、BlazeFace 或預先存在的地面實況邊界框。
import face_alignment
# sfd for SFD, dlib for Dlib and folder for existing bounding boxes.
fa = face_alignment . FaceAlignment ( face_alignment . LandmarksType . TWO_D , face_detector = 'sfd' )
為了指定運行代碼的設備(GPU 或 CPU),可以明確傳遞設備標誌:
import torch
import face_alignment
# cuda for CUDA, mps for Apple M1/2 GPUs.
fa = face_alignment . FaceAlignment ( face_alignment . LandmarksType . TWO_D , device = 'cpu' )
# running using lower precision
fa = fa = face_alignment . FaceAlignment ( face_alignment . LandmarksType . TWO_D , dtype = torch . bfloat16 , device = 'cuda' )
另請參閱examples
夾
# dlib (fast, may miss faces)
model = FaceAlignment ( landmarks_type = LandmarksType . TWO_D , face_detector = 'dlib' )
# SFD (likely best results, but slowest)
model = FaceAlignment ( landmarks_type = LandmarksType . TWO_D , face_detector = 'sfd' )
# Blazeface (front camera model)
model = FaceAlignment ( landmarks_type = LandmarksType . TWO_D , face_detector = 'blazeface' )
# Blazeface (back camera model)
model = FaceAlignment ( landmarks_type = LandmarksType . TWO_D , face_detector = 'blazeface' , face_detector_kwargs = { 'back_model' : True })
雖然不是必需的,但為了獲得最佳效能(尤其是偵測器),強烈建議使用支援 CUDA 的 GPU 運行程式碼。
最簡單的安裝方法是使用 pip 或 conda:
使用點 | 使用康達 |
---|---|
pip install face-alignment | conda install -c 1adrianb face_alignment |
或者,您可以在下面找到從原始程式碼建置它的說明。
安裝 pytorch 和 pytorch 依賴項。請檢查 pytorch 自述文件。
git clone https://github.com/1adrianb/face-alignment
pip install -r requirements.txt
python setup.py install
提供了一個 Dockerfile 來建立具有 cuda 支援和 cudnn 的映像。有關運行和建置 docker 映像的更多說明,請查看原始 Docker 文件。
docker build -t face-alignment .
雖然這裡的工作是作為黑盒子呈現的,但如果您想了解更多有關該方法的細節,請查看 arxiv 或我的網頁上的原始論文。
歡迎所有貢獻。如果您遇到任何問題(包括失敗的圖像範例),請隨時提出問題。如果您打算新增功能,請在提出拉取請求之前開啟問題進行討論。
@inproceedings{bulat2017far,
title={How far are we from solving the 2D & 3D Face Alignment problem? (and a dataset of 230,000 3D facial landmarks)},
author={Bulat, Adrian and Tzimiropoulos, Georgios},
booktitle={International Conference on Computer Vision},
year={2017}
}
要引用 dlib、pytorch 或此處使用的任何其他包,請查看其各自作者的原始頁面。