33
33
34
34
def parse_args () -> None :
35
35
signal .signal (signal .SIGINT , lambda signal_number , frame : destroy ())
36
- program = argparse .ArgumentParser ()
36
+ program = argparse .ArgumentParser (formatter_class = lambda prog : argparse . HelpFormatter ( prog , max_help_position = 100 ) )
37
37
program .add_argument ('-s' , '--source' , help = 'select an source image' , dest = 'source_path' )
38
38
program .add_argument ('-t' , '--target' , help = 'select an target image or video' , dest = 'target_path' )
39
39
program .add_argument ('-o' , '--output' , help = 'select output file or directory' , dest = 'output_path' )
40
- program .add_argument ('--frame-processor' , help = 'pipeline of frame processors' , dest = 'frame_processor' , default = ['face_swapper' ], choices = [ 'face_swapper' , 'face_enhancer ' ], nargs = '+' )
40
+ program .add_argument ('--frame-processor' , help = 'frame processors (choices: face_swapper, face_enhancer, ...) ' , dest = 'frame_processor' , default = ['face_swapper' ], nargs = '+' )
41
41
program .add_argument ('--keep-fps' , help = 'keep original fps' , dest = 'keep_fps' , action = 'store_true' , default = False )
42
42
program .add_argument ('--keep-audio' , help = 'keep original audio' , dest = 'keep_audio' , action = 'store_true' , default = True )
43
43
program .add_argument ('--keep-frames' , help = 'keep temporary frames' , dest = 'keep_frames' , action = 'store_true' , default = False )
44
44
program .add_argument ('--many-faces' , help = 'process every face' , dest = 'many_faces' , action = 'store_true' , default = False )
45
45
program .add_argument ('--video-encoder' , help = 'adjust output video encoder' , dest = 'video_encoder' , default = 'libx264' , choices = ['libx264' , 'libx265' , 'libvpx-vp9' ])
46
46
program .add_argument ('--video-quality' , help = 'adjust output video quality' , dest = 'video_quality' , type = int , default = 18 , choices = range (52 ), metavar = '[0-51]' )
47
47
program .add_argument ('--max-memory' , help = 'maximum amount of RAM in GB' , dest = 'max_memory' , type = int , default = suggest_max_memory ())
48
- program .add_argument ('--execution-provider' , help = 'execution provider' , dest = 'execution_provider' , default = ['cpu' ], choices = suggest_execution_providers (), nargs = '+' )
48
+ program .add_argument ('--execution-provider' , help = 'available execution provider (choices: cpu, ...) ' , dest = 'execution_provider' , default = ['cpu' ], choices = suggest_execution_providers (), nargs = '+' )
49
49
program .add_argument ('--execution-threads' , help = 'number of execution threads' , dest = 'execution_threads' , type = int , default = suggest_execution_threads ())
50
50
program .add_argument ('-v' , '--version' , action = 'version' , version = f'{ roop .metadata .name } { roop .metadata .version } ' )
51
51
52
- # register deprecated args
53
- program .add_argument ('-f' , '--face' , help = argparse .SUPPRESS , dest = 'source_path_deprecated' )
54
- program .add_argument ('--cpu-cores' , help = argparse .SUPPRESS , dest = 'cpu_cores_deprecated' , type = int )
55
- program .add_argument ('--gpu-vendor' , help = argparse .SUPPRESS , dest = 'gpu_vendor_deprecated' )
56
- program .add_argument ('--gpu-threads' , help = argparse .SUPPRESS , dest = 'gpu_threads_deprecated' , type = int )
57
-
58
52
args = program .parse_args ()
59
53
60
54
roop .globals .source_path = args .source_path
@@ -72,27 +66,6 @@ def parse_args() -> None:
72
66
roop .globals .execution_providers = decode_execution_providers (args .execution_provider )
73
67
roop .globals .execution_threads = args .execution_threads
74
68
75
- # translate deprecated args
76
- if args .source_path_deprecated :
77
- print ('\033 [33mArgument -f and --face are deprecated. Use -s and --source instead.\033 [0m' )
78
- roop .globals .source_path = args .source_path_deprecated
79
- roop .globals .output_path = normalize_output_path (args .source_path_deprecated , roop .globals .target_path , args .output_path )
80
- if args .cpu_cores_deprecated :
81
- print ('\033 [33mArgument --cpu-cores is deprecated. Use --execution-threads instead.\033 [0m' )
82
- roop .globals .execution_threads = args .cpu_cores_deprecated
83
- if args .gpu_vendor_deprecated == 'apple' :
84
- print ('\033 [33mArgument --gpu-vendor apple is deprecated. Use --execution-provider coreml instead.\033 [0m' )
85
- roop .globals .execution_providers = decode_execution_providers (['coreml' ])
86
- if args .gpu_vendor_deprecated == 'nvidia' :
87
- print ('\033 [33mArgument --gpu-vendor nvidia is deprecated. Use --execution-provider cuda instead.\033 [0m' )
88
- roop .globals .execution_providers = decode_execution_providers (['cuda' ])
89
- if args .gpu_vendor_deprecated == 'amd' :
90
- print ('\033 [33mArgument --gpu-vendor amd is deprecated. Use --execution-provider cuda instead.\033 [0m' )
91
- roop .globals .execution_providers = decode_execution_providers (['rocm' ])
92
- if args .gpu_threads_deprecated :
93
- print ('\033 [33mArgument --gpu-threads is deprecated. Use --execution-threads instead.\033 [0m' )
94
- roop .globals .execution_threads = args .gpu_threads_deprecated
95
-
96
69
97
70
def encode_execution_providers (execution_providers : List [str ]) -> List [str ]:
98
71
return [execution_provider .replace ('ExecutionProvider' , '' ).lower () for execution_provider in execution_providers ]
@@ -125,7 +98,9 @@ def limit_resources() -> None:
125
98
# prevent tensorflow memory leak
126
99
gpus = tensorflow .config .experimental .list_physical_devices ('GPU' )
127
100
for gpu in gpus :
128
- tensorflow .config .experimental .set_memory_growth (gpu , True )
101
+ tensorflow .config .experimental .set_virtual_device_configuration (gpu , [
102
+ tensorflow .config .experimental .VirtualDeviceConfiguration (memory_limit = 1024 )
103
+ ])
129
104
# limit memory usage
130
105
if roop .globals .max_memory :
131
106
memory = roop .globals .max_memory * 1024 ** 3
@@ -173,6 +148,7 @@ def start() -> None:
173
148
for frame_processor in get_frame_processors_modules (roop .globals .frame_processors ):
174
149
update_status ('Progressing...' , frame_processor .NAME )
175
150
frame_processor .process_image (roop .globals .source_path , roop .globals .output_path , roop .globals .output_path )
151
+ frame_processor .post_process ()
176
152
release_resources ()
177
153
if is_image (roop .globals .target_path ):
178
154
update_status ('Processing to image succeed!' )
@@ -190,6 +166,7 @@ def start() -> None:
190
166
for frame_processor in get_frame_processors_modules (roop .globals .frame_processors ):
191
167
update_status ('Progressing...' , frame_processor .NAME )
192
168
frame_processor .process_video (roop .globals .source_path , temp_frame_paths )
169
+ frame_processor .post_process ()
193
170
release_resources ()
194
171
# handles fps
195
172
if roop .globals .keep_fps :
0 commit comments