diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-10-04 09:32:22 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-10-04 09:32:22 +0000 |
commit | 6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77 (patch) | |
tree | 5c221ca22288633f8814cc1f304590bf5f26b73c /modules/gfpgan_model.py | |
parent | 556c36b9607e3f4eacdddc85f8e7a78b29476ea7 (diff) | |
download | stable-diffusion-webui-gfx803-6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77.tar.gz stable-diffusion-webui-gfx803-6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77.tar.bz2 stable-diffusion-webui-gfx803-6c6ae28bf5fd1e8bc3e8f64a3430b6f29f338f77.zip |
send all three of GFPGAN's and codeformer's models to CPU memory instead of just one for #1283
Diffstat (limited to 'modules/gfpgan_model.py')
-rw-r--r-- | modules/gfpgan_model.py | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/gfpgan_model.py b/modules/gfpgan_model.py index dd3fbcab..5586b554 100644 --- a/modules/gfpgan_model.py +++ b/modules/gfpgan_model.py @@ -37,22 +37,32 @@ def gfpgann(): print("Unable to load gfpgan model!")
return None
model = gfpgan_constructor(model_path=model_file, upscale=1, arch='clean', channel_multiplier=2, bg_upsampler=None)
- model.gfpgan.to(shared.device)
loaded_gfpgan_model = model
return model
+def send_model_to(model, device):
+ model.gfpgan.to(device)
+ model.face_helper.face_det.to(device)
+ model.face_helper.face_parse.to(device)
+
+
def gfpgan_fix_faces(np_image):
model = gfpgann()
if model is None:
return np_image
+
+ send_model_to(model, devices.device)
+
np_image_bgr = np_image[:, :, ::-1]
cropped_faces, restored_faces, gfpgan_output_bgr = model.enhance(np_image_bgr, has_aligned=False, only_center_face=False, paste_back=True)
np_image = gfpgan_output_bgr[:, :, ::-1]
+ model.face_helper.clean_all()
+
if shared.opts.face_restoration_unload:
- model.gfpgan.to(devices.cpu)
+ send_model_to(model, devices.cpu)
return np_image
|