To run the 3D Dense Face Alignment, you need to load a configuration file and initialize both the FaceBoxes detector and the TDDFA model. It is recommended to use the onnx flag for improved speed. If using ONNX, you may need to set specific environment variables for thread management.
import yaml
import os
from FaceBoxes.FaceBoxes_ONNX import FaceBoxes_ONNX
from TDDFA_ONNX import TDDFA_ONNX
from TDDFA import TDDFA
from FaceBoxes import FaceBoxes
# Load config
cfg = yaml.load(open('configs/mb1_120x120.yml'), Loader=yaml.SafeLoader)
# Recommended: Use ONNX for speed
onnx_flag = True
if onnx_flag:
os.environ['KMP_DUPLICATE_LIB_OK'] = 'True'
os.environ['OMP_NUM_THREADS'] = '4'
face_boxes = FaceBoxes_ONNX()
tddfa = TDDFA_ONNX(**cfg)
else:
tddfa = TDDFA(gpu_mode=False, **cfg)
face_boxes = FaceBoxes()