Make Face Enhancer Model device Conditional
Added Co-Author Co-Authored-By: Rishon <rishon@rishon.me>pull/844/head
							parent
							
								
									681c20dbbd
								
							
						
					
					
						commit
						84ca1dc2f2
					
				|  | @ -9,6 +9,8 @@ import modules.processors.frame.core | |||
| from modules.core import update_status | ||||
| from modules.face_analyser import get_one_face | ||||
| from modules.typing import Frame, Face | ||||
| import platform | ||||
| import torch | ||||
| from modules.utilities import ( | ||||
|     conditional_download, | ||||
|     is_image, | ||||
|  | @ -21,7 +23,10 @@ THREAD_LOCK = threading.Lock() | |||
| NAME = "DLC.FACE-ENHANCER" | ||||
| 
 | ||||
| abs_dir = os.path.dirname(os.path.abspath(__file__)) | ||||
| models_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(abs_dir))), 'models') | ||||
| models_dir = os.path.join( | ||||
|     os.path.dirname(os.path.dirname(os.path.dirname(abs_dir))), "models" | ||||
| ) | ||||
| 
 | ||||
| 
 | ||||
| def pre_check() -> bool: | ||||
|     download_directory_path = models_dir | ||||
|  | @ -48,7 +53,13 @@ def get_face_enhancer() -> Any: | |||
| 
 | ||||
|     with THREAD_LOCK: | ||||
|         if FACE_ENHANCER is None: | ||||
|             model_path = os.path.join(models_dir, 'GFPGANv1.4.pth') | ||||
|             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] | ||||
|     return FACE_ENHANCER | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue