forked from minoring/PRNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
34 lines (29 loc) · 1.18 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import os
from predictor import PosPrediction
class PRN(object):
"""Joint 3D Face Reconstruction and Dense Alighment with Position Map Regression Network
"""
def __init__(self, is_Dlib=False, prefix='.'):
"""
Args:
is_dlib(bool, optional): if True, dlib is used for detecting faces.
prefix(str, optional): If run at another folder, the absolute path is needed to load the data.
"""
# Resolution of input and output image size.
self.resolution_input = 256
self.resolution_output = 256
# Load detectors
if is_Dlib:
import dlib
detector_path = os.path.join(
prefix, 'Data/net-data/mmod_human_face_detector.dat')
self.face_detector = dlib.cnn_face_detection_model_v1(
detector_path) # TODO Invest more and try other face detector.
# Load PRN
self.pos_predictor = PosPrediction(self.resolution_input,
self.resolution_output)
prn_path = os.path.join(prefix, 'Data/net-data/256_256_resfcn256_weight')
if not os.path.isfile(prn_path + '.data-00000-of-00001'):
print('Please download PRN trained model first.')
exit()
self.pos_predictor.restore(prn_path)