-
Notifications
You must be signed in to change notification settings - Fork 17
/
run_faceswapper.py
106 lines (101 loc) · 4.3 KB
/
run_faceswapper.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import argparse
from dofaker import FaceSwapper
def parse_args():
parser = argparse.ArgumentParser(description='running face swap')
parser.add_argument('--source',
help='select an image or video to be swapped',
dest='source',
required=True)
parser.add_argument('--dst_face_paths',
help='select images in source to be swapped',
dest='dst_face_paths',
nargs='+',
default=None)
parser.add_argument(
'--src_face_paths',
help='select images to replace dst_faces in source image or video.',
dest='src_face_paths',
nargs='+',
required=True)
parser.add_argument('--output_dir',
help='output directory',
dest='output_dir',
default='output')
parser.add_argument('--det_model_name',
help='detection model name for insightface',
dest='det_model_name',
default='buffalo_l')
parser.add_argument('--det_model_dir',
help='detection model dir for insightface',
dest='det_model_dir',
default='weights/models')
parser.add_argument('--swap_model_name',
help='swap model name',
dest='swap_model_name',
default='inswapper')
parser.add_argument('--image_sr_model',
help='image super resolution model',
dest='image_sr_model',
default='bsrgan')
parser.add_argument('--face_swap_model_dir',
help='swap model path',
dest='face_swap_model_dir',
default='weights/models')
parser.add_argument('--image_sr_model_dir',
help='image super resolution model dir',
dest='image_sr_model_dir',
default='weights/models')
parser.add_argument('--face_enhance_name',
help='face enhance model',
dest='face_enhance_name',
default='gfpgan')
parser.add_argument('--face_enhance_model_dir',
help='face enhance model dir',
dest='face_enhance_model_dir',
default='weights/models')
parser.add_argument('--face_sim_thre',
help='similarity of face embedding threshold',
dest='face_sim_thre',
default=0.5)
parser.add_argument('--log_iters',
help='print log intervals',
dest='log_iters',
default=10,
type=int)
parser.add_argument('--use_enhancer',
help='whether use face enhance model',
dest='use_enhancer',
action='store_true')
parser.add_argument('--use_sr',
help='whether use image super resolution model',
dest='use_sr',
action='store_true')
parser.add_argument('--sr_scale',
help='image super resolution scale',
dest='sr_scale',
default=1,
type=float)
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
faker = FaceSwapper(
face_det_model=args.det_model_name,
face_det_model_dir=args.det_model_dir,
face_swap_model=args.swap_model_name,
face_swap_model_dir=args.face_swap_model_dir,
image_sr_model=args.image_sr_model,
image_sr_model_dir=args.image_sr_model_dir,
face_enhance_model=args.face_enhance_name,
face_enhance_model_dir=args.face_enhance_model_dir,
face_sim_thre=args.face_sim_thre,
log_iters=args.log_iters,
use_enhancer=args.use_enhancer,
use_sr=args.use_sr,
scale=args.sr_scale,
)
faker.run(
input_path=args.source,
dst_face_paths=args.dst_face_paths,
src_face_paths=args.src_face_paths,
output_dir=args.output_dir,
)