From 07c735e9d2a90fb38be949915d05b83511486faa Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Sep 2024 18:31:06 +0100 Subject: [PATCH] Allows to set the upscale factor for gfpgan face_enhancer --- modules/core.py | 5 ++++- modules/globals.py | 3 ++- modules/processors/frame/face_enhancer.py | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/core.py b/modules/core.py index a66340e..8c569b3 100644 --- a/modules/core.py +++ b/modules/core.py @@ -71,6 +71,9 @@ def parse_args() -> None: program.add_argument('--execution-threads', help='Number of execution threads', dest='execution_threads', type=int, default=suggest_execution_threads()) program.add_argument('--headless', help='Run in headless mode', dest='headless', default=False, action='store_true') + program.add_argument('--enhancer_upscale_factor', + help='Sets the upscale factor for the enhancer. Only applies if `face_enhancer` is set as a frame_processor', + dest='enhancer_upscale_factor', type=int, default=1) program.add_argument('-v', '--version', action='version', version=f'{modules.metadata.name} {modules.metadata.version}') @@ -100,7 +103,7 @@ def parse_args() -> None: modules.globals.execution_providers = decode_execution_providers(args.execution_provider) modules.globals.execution_threads = args.execution_threads modules.globals.headless = args.headless - + modules.globals.enhancer_upscale_factor = args.enhancer_upscale_factor # Handle face enhancer tumbler modules.globals.fp_ui['face_enhancer'] = 'face_enhancer' in args.frame_processor diff --git a/modules/globals.py b/modules/globals.py index 2bc15fd..a435e4d 100644 --- a/modules/globals.py +++ b/modules/globals.py @@ -29,4 +29,5 @@ log_level = 'error' fp_ui: Dict[str, bool] = {} nsfw = None camera_input_combobox = None -webcam_preview_running = False \ No newline at end of file +webcam_preview_running = False +enhancer_upscale_factor = 1 diff --git a/modules/processors/frame/face_enhancer.py b/modules/processors/frame/face_enhancer.py index a75f5c0..a39bef6 100644 --- a/modules/processors/frame/face_enhancer.py +++ b/modules/processors/frame/face_enhancer.py @@ -33,7 +33,10 @@ def get_face_enhancer() -> Any: with THREAD_LOCK: if FACE_ENHANCER is None: model_path = resolve_relative_path('../models/GFPGANv1.4.pth') - FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined] + FACE_ENHANCER = gfpgan.GFPGANer( + model_path=model_path, + upscale=modules.globals.enhancer_upscale_factor + ) # type: ignore[attr-defined] return FACE_ENHANCER def enhance_face(temp_frame: Frame) -> Frame: