aboutsummaryrefslogtreecommitdiffstats
path: root/modules/modelloader.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2022-10-06 17:30:29 +0000
committerGitHub <noreply@github.com>2022-10-06 17:30:29 +0000
commitab4ddbf333eef170804ef8de67001f77c8fdd64c (patch)
tree21cb1109f8eae463aa4066eec0926cd71ab81740 /modules/modelloader.py
parent2a7f48cdb8dcf9acb02610cccae0d1ee5d260bc2 (diff)
parentcf7c784fcc0c84a8a4edd8d3aca4dda4c7025c43 (diff)
downloadstable-diffusion-webui-gfx803-ab4ddbf333eef170804ef8de67001f77c8fdd64c.tar.gz
stable-diffusion-webui-gfx803-ab4ddbf333eef170804ef8de67001f77c8fdd64c.tar.bz2
stable-diffusion-webui-gfx803-ab4ddbf333eef170804ef8de67001f77c8fdd64c.zip
Merge branch 'master' into gallery-styling
Diffstat (limited to 'modules/modelloader.py')
-rw-r--r--modules/modelloader.py24
1 files changed, 19 insertions, 5 deletions
diff --git a/modules/modelloader.py b/modules/modelloader.py
index 1106aeb7..b0f2f33d 100644
--- a/modules/modelloader.py
+++ b/modules/modelloader.py
@@ -1,10 +1,10 @@
+import glob
import os
import shutil
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
@@ -41,8 +41,8 @@ def load_models(model_path: str, model_url: str = None, command_path: str = None
for place in places:
if os.path.exists(place):
- for file in os.listdir(place):
- full_path = os.path.join(place, file)
+ for file in glob.iglob(place + '**/**', recursive=True):
+ full_path = file
if os.path.isdir(full_path):
continue
if len(ext_filter) != 0:
@@ -120,16 +120,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)