diff options
author | AUTOMATIC1111 <16777216c@gmail.com> | 2023-06-27 06:20:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-27 06:20:49 +0000 |
commit | 3cd4fd51ef916aba8b978490569a5da82795a839 (patch) | |
tree | cdae174b0c146f11bbda49f52bbcb389cc2f9893 /extensions-builtin/ScuNET/scripts | |
parent | d4f9250c5aef0fd3afb6ed8a6bc3515fa2fcf635 (diff) | |
parent | 2667f47ffbf7c641a7e77abbdddf5e81bf144199 (diff) | |
download | stable-diffusion-webui-gfx803-3cd4fd51ef916aba8b978490569a5da82795a839.tar.gz stable-diffusion-webui-gfx803-3cd4fd51ef916aba8b978490569a5da82795a839.tar.bz2 stable-diffusion-webui-gfx803-3cd4fd51ef916aba8b978490569a5da82795a839.zip |
Merge pull request #10823 from akx/model-loady
Upscaler model loading cleanup
Diffstat (limited to 'extensions-builtin/ScuNET/scripts')
-rw-r--r-- | extensions-builtin/ScuNET/scripts/scunet_model.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/extensions-builtin/ScuNET/scripts/scunet_model.py b/extensions-builtin/ScuNET/scripts/scunet_model.py index 85b4505f..ffef26b2 100644 --- a/extensions-builtin/ScuNET/scripts/scunet_model.py +++ b/extensions-builtin/ScuNET/scripts/scunet_model.py @@ -1,4 +1,3 @@ -import os.path import sys import PIL.Image @@ -6,12 +5,11 @@ import numpy as np import torch from tqdm import tqdm -from basicsr.utils.download_util import load_file_from_url - import modules.upscaler from modules import devices, modelloader, script_callbacks, errors -from scunet_model_arch import SCUNet as net +from scunet_model_arch import SCUNet +from modules.modelloader import load_file_from_url from modules.shared import opts @@ -28,7 +26,7 @@ class UpscalerScuNET(modules.upscaler.Upscaler): scalers = [] add_model2 = True for file in model_paths: - if "http" in file: + if file.startswith("http"): name = self.model_name else: name = modelloader.friendly_name(file) @@ -89,9 +87,10 @@ class UpscalerScuNET(modules.upscaler.Upscaler): torch.cuda.empty_cache() - model = self.load_model(selected_file) - if model is None: - print(f"ScuNET: Unable to load model from {selected_file}", file=sys.stderr) + try: + model = self.load_model(selected_file) + except Exception as e: + print(f"ScuNET: Unable to load model from {selected_file}: {e}", file=sys.stderr) return img device = devices.get_device_for('scunet') @@ -119,15 +118,12 @@ class UpscalerScuNET(modules.upscaler.Upscaler): def load_model(self, path: str): device = devices.get_device_for('scunet') - if "http" in path: - filename = load_file_from_url(url=self.model_url, model_dir=self.model_download_path, file_name="%s.pth" % self.name, progress=True) + if path.startswith("http"): + # TODO: this doesn't use `path` at all? + filename = load_file_from_url(self.model_url, model_dir=self.model_download_path, file_name=f"{self.name}.pth") else: filename = path - if not os.path.exists(os.path.join(self.model_path, filename)) or filename is None: - print(f"ScuNET: Unable to load model from {filename}", file=sys.stderr) - return None - - model = net(in_nc=3, config=[4, 4, 4, 4, 4, 4, 4], dim=64) + model = SCUNet(in_nc=3, config=[4, 4, 4, 4, 4, 4, 4], dim=64) model.load_state_dict(torch.load(filename), strict=True) model.eval() for _, v in model.named_parameters(): |