diff options
author | AUTOMATIC <16777216c@gmail.com> | 2022-09-12 15:40:06 +0000 |
---|---|---|
committer | AUTOMATIC <16777216c@gmail.com> | 2022-09-12 15:40:06 +0000 |
commit | 843b2b64fcd41be4a9e934ba83a3a499c7aff5c0 (patch) | |
tree | 5981ba18a9729c80f49d87e0d0ffec36fcaf6206 /modules/gfpgan_model.py | |
parent | 535b25ad26d31d53ef0d02060d35571770e9c287 (diff) | |
download | stable-diffusion-webui-gfx803-843b2b64fcd41be4a9e934ba83a3a499c7aff5c0.tar.gz stable-diffusion-webui-gfx803-843b2b64fcd41be4a9e934ba83a3a499c7aff5c0.tar.bz2 stable-diffusion-webui-gfx803-843b2b64fcd41be4a9e934ba83a3a499c7aff5c0.zip |
Instance of CUDA out of memory on a low-res batch, even with --opt-split-attention-v1 (found cause) #255
Diffstat (limited to 'modules/gfpgan_model.py')
-rw-r--r-- | modules/gfpgan_model.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/modules/gfpgan_model.py b/modules/gfpgan_model.py index f697326c..0af97123 100644 --- a/modules/gfpgan_model.py +++ b/modules/gfpgan_model.py @@ -2,7 +2,7 @@ import os import sys
import traceback
-from modules import shared
+from modules import shared, devices
from modules.shared import cmd_opts
from modules.paths import script_path
import modules.face_restoration
@@ -28,24 +28,29 @@ def gfpgan(): global loaded_gfpgan_model
if loaded_gfpgan_model is not None:
+ loaded_gfpgan_model.gfpgan.to(shared.device)
return loaded_gfpgan_model
if gfpgan_constructor is None:
return None
model = gfpgan_constructor(model_path=gfpgan_model_path(), upscale=1, arch='clean', channel_multiplier=2, bg_upsampler=None)
-
- if not cmd_opts.unload_gfpgan:
- loaded_gfpgan_model = model
+ model.gfpgan.to(shared.device)
+ loaded_gfpgan_model = model
return model
def gfpgan_fix_faces(np_image):
+ model = gfpgan()
+
np_image_bgr = np_image[:, :, ::-1]
- cropped_faces, restored_faces, gfpgan_output_bgr = gfpgan().enhance(np_image_bgr, has_aligned=False, only_center_face=False, paste_back=True)
+ 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]
+ if shared.opts.face_restoration_unload:
+ model.gfpgan.to(devices.cpu)
+
return np_image
|