aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authord8ahazard <d8ahazard@gmail.com>2022-09-30 20:26:18 +0000
committerd8ahazard <d8ahazard@gmail.com>2022-09-30 20:26:18 +0000
commite82ea202997cbcd2ab72891cd075d9ba270eb67d (patch)
treef367eeae535d35fffe8d9217740e5bf76f89fbd2
parent3a876b16a92a23e5536d828c9217fda998e5d9c1 (diff)
downloadstable-diffusion-webui-gfx803-e82ea202997cbcd2ab72891cd075d9ba270eb67d.tar.gz
stable-diffusion-webui-gfx803-e82ea202997cbcd2ab72891cd075d9ba270eb67d.tar.bz2
stable-diffusion-webui-gfx803-e82ea202997cbcd2ab72891cd075d9ba270eb67d.zip
Optimize model loader
Child classes only get populated to __subclassess__ when they are imported. We don't actually need to import any of them to webui any more, so clean up webUI imports and make sure loader imports children. Also, fix command line paths not actually being passed to the scalers.
-rw-r--r--modules/modelloader.py19
-rw-r--r--webui.py13
2 files changed, 19 insertions, 13 deletions
diff --git a/modules/modelloader.py b/modules/modelloader.py
index 1106aeb7..b1721671 100644
--- a/modules/modelloader.py
+++ b/modules/modelloader.py
@@ -4,7 +4,6 @@ import importlib
from urllib.parse import urlparse
from basicsr.utils.download_util import load_file_from_url
-
from modules import shared
from modules.upscaler import Upscaler
from modules.paths import script_path, models_path
@@ -120,16 +119,30 @@ def move_files(src_path: str, dest_path: str, ext_filter: str = None):
def load_upscalers():
+ sd = shared.script_path
+ # We can only do this 'magic' method to dynamically load upscalers if they are referenced,
+ # so we'll try to import any _model.py files before looking in __subclasses__
+ modules_dir = os.path.join(sd, "modules")
+ for file in os.listdir(modules_dir):
+ if "_model.py" in file:
+ model_name = file.replace("_model.py", "")
+ full_model = f"modules.{model_name}_model"
+ try:
+ importlib.import_module(full_model)
+ except:
+ pass
datas = []
+ c_o = vars(shared.cmd_opts)
for cls in Upscaler.__subclasses__():
name = cls.__name__
module_name = cls.__module__
module = importlib.import_module(module_name)
class_ = getattr(module, name)
- cmd_name = f"{name.lower().replace('upscaler', '')}-models-path"
+ cmd_name = f"{name.lower().replace('upscaler', '')}_models_path"
opt_string = None
try:
- opt_string = shared.opts.__getattr__(cmd_name)
+ if cmd_name in c_o:
+ opt_string = c_o[cmd_name]
except:
pass
scaler = class_(opt_string)
diff --git a/webui.py b/webui.py
index b8cccd54..ebe39a17 100644
--- a/webui.py
+++ b/webui.py
@@ -1,28 +1,21 @@
import os
-import threading
-
-from modules import devices
-from modules.paths import script_path
import signal
import threading
-import modules.paths
+
import modules.codeformer_model as codeformer
-import modules.esrgan_model as esrgan
-import modules.bsrgan_model as bsrgan
import modules.extras
import modules.face_restoration
import modules.gfpgan_model as gfpgan
import modules.img2img
-import modules.ldsr_model as ldsr
import modules.lowvram
-import modules.realesrgan_model as realesrgan
+import modules.paths
import modules.scripts
import modules.sd_hijack
import modules.sd_models
import modules.shared as shared
-import modules.swinir_model as swinir
import modules.txt2img
import modules.ui
+from modules import devices
from modules import modelloader
from modules.paths import script_path
from modules.shared import cmd_opts