forked from iperov/DeepFaceLive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
98 lines (74 loc) · 3.6 KB
/
main.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
import argparse
import os
import platform
from pathlib import Path
from xlib import appargs as lib_appargs
from xlib import os as lib_os
# onnxruntime==1.8.0 requires CUDA_PATH_V11_2, but 1.8.1 don't
# keep the code if they return that behaviour
# if __name__ == '__main__':
# if platform.system() == 'Windows':
# if 'CUDA_PATH' not in os.environ:
# raise Exception('CUDA_PATH should be set to environ')
# # set environ for onnxruntime
# # os.environ['CUDA_PATH_V11_2'] = os.environ['CUDA_PATH']
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()
run_parser = subparsers.add_parser( "run", help="Run the application.")
run_subparsers = run_parser.add_subparsers()
def run_DeepFaceLive(args):
userdata_path = Path(args.userdata_dir)
lib_appargs.set_arg_bool('NO_CUDA', args.no_cuda)
print('Running DeepFaceLive.')
from apps.DeepFaceLive.DeepFaceLiveApp import DeepFaceLiveApp
DeepFaceLiveApp(userdata_path=userdata_path).run()
p = run_subparsers.add_parser('DeepFaceLive')
p.add_argument('--userdata-dir', default=None, action=fixPathAction, help="Workspace directory.")
p.add_argument('--no-cuda', action="store_true", default=False, help="Disable CUDA.")
p.set_defaults(func=run_DeepFaceLive)
dev_parser = subparsers.add_parser("dev")
dev_subparsers = dev_parser.add_subparsers()
def run_split_large_files(args):
from scripts import dev
dev.split_large_files()
p = dev_subparsers.add_parser('split_large_files')
p.set_defaults(func=run_split_large_files)
def run_merge_large_files(args):
from scripts import dev
dev.merge_large_files(delete_parts=args.delete_parts)
p = dev_subparsers.add_parser('merge_large_files')
p.add_argument('--delete-parts', action="store_true", default=False)
p.set_defaults(func=run_merge_large_files)
def run_extract_FaceSynthetics(args):
from scripts import dev
inputdir_path = Path(args.input_dir)
faceset_path = Path(args.faceset_path)
dev.extract_FaceSynthetics(inputdir_path, faceset_path)
p = dev_subparsers.add_parser('extract_FaceSynthetics')
p.add_argument('--input-dir', default=None, action=fixPathAction, help="FaceSynthetics directory.")
p.add_argument('--faceset-path', default=None, action=fixPathAction, help="output .dfs path")
p.set_defaults(func=run_extract_FaceSynthetics)
train_parser = subparsers.add_parser( "train", help="Train neural network.")
train_parsers = train_parser.add_subparsers()
def train_FaceAligner(args):
lib_os.set_process_priority(lib_os.ProcessPriority.IDLE)
from apps.trainers.FaceAligner.FaceAlignerTrainerApp import FaceAlignerTrainerApp
FaceAlignerTrainerApp(workspace_path=Path(args.workspace_dir), faceset_path=Path(args.faceset_path))
p = train_parsers.add_parser('FaceAligner')
p.add_argument('--workspace-dir', default=None, action=fixPathAction, help="Workspace directory.")
p.add_argument('--faceset-path', default=None, action=fixPathAction, help=".dfs path")
p.set_defaults(func=train_FaceAligner)
def bad_args(arguments):
parser.print_help()
exit(0)
parser.set_defaults(func=bad_args)
args = parser.parse_args()
args.func(args)
class fixPathAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
if __name__ == '__main__':
main()
# import code
# code.interact(local=dict(globals(), **locals()))