-
Notifications
You must be signed in to change notification settings - Fork 29
/
preprocess_in_the_wild.py
58 lines (49 loc) · 2.29 KB
/
preprocess_in_the_wild.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# SPDX-FileCopyrightText: Copyright (c) 2021-2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NvidiaProprietary
#
# NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
# property and proprietary rights in and to this material, related
# documentation and any modifications thereto. Any use, reproduction,
# disclosure or distribution of this material and related documentation
# without an express license agreement from NVIDIA CORPORATION or
# its affiliates is strictly prohibited.
import os
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--indir', type=str, required=True)
args = parser.parse_args()
# run mtcnn needed for Deep3DFaceRecon
command = "python batch_mtcnn.py --in_root " + args.indir
print(command)
os.system(command)
out_folder = args.indir.split("/")[-2] if args.indir.endswith("/") else args.indir.split("/")[-1]
# run Deep3DFaceRecon
os.chdir('Deep3DFaceRecon_pytorch')
command = "python test.py --img_folder=" + args.indir + " --gpu_ids=0 --name=pretrained --epoch=20"
print(command)
os.system(command)
os.chdir('..')
# crop out the input image
command = "python crop_images_in_the_wild.py --indir=" + args.indir
print(command)
os.system(command)
# convert the pose to our format
command = f"python 3dface2idr_mat.py --in_root Deep3DFaceRecon_pytorch/checkpoints/pretrained/results/{out_folder}/epoch_20_000000 --out_path {os.path.join(args.indir, 'crop', 'cameras.json')}"
print(command)
os.system(command)
# additional correction to match the submission version
command = f"python preprocess_face_cameras.py --source {os.path.join(args.indir, 'crop')} --dest {out_folder} --mode orig"
print(command)
os.system(command)
# estimate gaze direction
os.chdir('faceverse')
command = f"python fit_imgs_offline_cuda.py --input {os.path.join(args.indir, 'crop')} --res_folder {os.path.join(args.indir, 'gaze_results')}"
print(command)
os.system(command)
os.chdir('..')
# estimate FLAME parameters by DECA
os.chdir('deca')
command = f"python demo_reconstruct.py -i {os.path.join(args.indir, 'crop')} -s {os.path.join(args.indir, 'deca_results')} --saveObj 1 --saveKpt 1 --load_eye_pose 1 --eyepath {os.path.join(args.indir, 'gaze_results/param')} --rasterizer_type pytorch3d"
print(command)
os.system(command)
os.chdir('..')