-
Notifications
You must be signed in to change notification settings - Fork 31
/
export_to_facewarper_single.py
69 lines (63 loc) · 2.47 KB
/
export_to_facewarper_single.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
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import torch
from torch.autograd import (Variable,
grad)
import imp
import argparse
import os
import glob
from depthnet_gan import DepthNetGAN
from depthnet_gan_learnm import DepthNetGAN_M
from interactive import warp_to_target_face
'''
Process arguments.
'''
def parse_args():
parser = argparse.ArgumentParser(description="")
parser.add_argument('--src_kpts_file', type=str, required=True)
parser.add_argument('--tgt_kpts_file', type=str, required=True)
parser.add_argument('--src_img_file', type=str, required=True)
parser.add_argument('--tgt_img_file', type=str, required=True)
parser.add_argument('--output_dir', type=str, required=True)
parser.add_argument('--output_size', type=str, default='tgt',
help="Output size of the warp. Can be an integer, or 'tgt' or 'src'.")
parser.add_argument('--checkpoint', type=str, required=True)
parser.add_argument('--kpt_file_separator', type=str, default=',',
help="The separator used for the keypoint files. For example, if " +
"these are CSV then ',' should be used (which is the default value).")
parser.add_argument('--learn_m', action='store_true')
parser.add_argument('--network', type=str, required=True)
parser.add_argument('--cpu', action='store_true')
args = parser.parse_args()
return args
args = parse_args()
# Dynamically load network module.
net_module = imp.load_source('network', args.network)
gen_fn, disc_fn = getattr(net_module, 'get_network')()
if args.learn_m:
gan_class = DepthNetGAN_M
else:
gan_class = DepthNetGAN
gan_kwargs = {
'g_fn': gen_fn,
'd_fn': disc_fn,
'use_cuda': False if args.cpu else 'detect'
}
net = gan_class(**gan_kwargs)
if args.checkpoint is not None:
print("Loading model: %s" % args.checkpoint)
net.load(args.checkpoint)
if args.output_size not in ['src', 'tgt']:
output_size = float(args.output_size)
else:
output_size = args.output_size
warp_to_target_face(net,
src_kpts_file=args.src_kpts_file,
tgt_kpts_file=args.tgt_kpts_file,
src_img_file=args.src_img_file,
tgt_img_file=args.tgt_img_file,
output_dir=args.output_dir,
output_size=output_size,
kpt_file_separator=args.kpt_file_separator,
basename_prefix='tgt',
save_plots=True)