From 41c69162735df3e118534a6da05e2171db9e9562 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Mon, 23 Dec 2024 06:08:45 +0000 Subject: [PATCH 1/2] Revert "Update face_enhancer.py" This reverts commit ed7a21687c4de9f32659c30a17571ce568c30b47. --- modules/processors/frame/face_enhancer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/processors/frame/face_enhancer.py b/modules/processors/frame/face_enhancer.py index fbc56e29..72e5efff 100644 --- a/modules/processors/frame/face_enhancer.py +++ b/modules/processors/frame/face_enhancer.py @@ -54,12 +54,12 @@ def get_face_enhancer() -> Any: with THREAD_LOCK: if FACE_ENHANCER is None: model_path = os.path.join(models_dir, "GFPGANv1.4.pth") - elif platform.system() == "Darwin": # Mac OS + if platform.system() == "Darwin": # Mac OS mps_device = None - elif torch.backends.mps.is_available(): + if torch.backends.mps.is_available(): mps_device = torch.device("mps") FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=mps_device) # type: ignore[attr-defined] - elif: # Other OS + else: # Other OS FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined] return FACE_ENHANCER From 7472dfb694546daadaf8e86415df5774d486f1c6 Mon Sep 17 00:00:00 2001 From: Pedro Santos Date: Mon, 23 Dec 2024 06:29:36 +0000 Subject: [PATCH 2/2] fix: add match statement Added for optimization Co-Authored-By: Zephira --- modules/processors/frame/face_enhancer.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/processors/frame/face_enhancer.py b/modules/processors/frame/face_enhancer.py index 72e5efff..4e1fdff6 100644 --- a/modules/processors/frame/face_enhancer.py +++ b/modules/processors/frame/face_enhancer.py @@ -54,13 +54,17 @@ def get_face_enhancer() -> Any: with THREAD_LOCK: if FACE_ENHANCER is None: model_path = os.path.join(models_dir, "GFPGANv1.4.pth") - if platform.system() == "Darwin": # Mac OS - mps_device = None - if torch.backends.mps.is_available(): - mps_device = torch.device("mps") - FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=mps_device) # type: ignore[attr-defined] - else: # Other OS - FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined] + + match platform.system(): + case "Darwin": # Mac OS + if torch.backends.mps.is_available(): + mps_device = torch.device("mps") + FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1, device=mps_device) # type: ignore[attr-defined] + else: + FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined] + case _: # Other OS + FACE_ENHANCER = gfpgan.GFPGANer(model_path=model_path, upscale=1) # type: ignore[attr-defined] + return FACE_ENHANCER