From 41f9449d96488017092d229d65f674c2e8252697 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 08:33:06 -0500 Subject: Fix LDSR YAML path --- modules/ldsr_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/ldsr_model.py b/modules/ldsr_model.py index 969d1a0d..877e7e73 100644 --- a/modules/ldsr_model.py +++ b/modules/ldsr_model.py @@ -24,7 +24,7 @@ class UpscalerLDSR(Upscaler): def load_model(self, path: str): model = load_file_from_url(url=self.model_url, model_dir=self.model_path, file_name="model.pth", progress=True) - yaml = load_file_from_url(url=self.model_url, model_dir=self.model_path, + yaml = load_file_from_url(url=self.yaml_url, model_dir=self.model_path, file_name="project.yaml", progress=True) try: -- cgit v1.2.1 From 64c6b13312ff3a20f48781c4c3780355c4b7b2af Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 08:41:25 -0500 Subject: Remove LDSR project.yaml if too large. If we accidentally downloaded the wrong file and saved it as project.yaml, this will delete it so it can be re-downloaded. --- modules/ldsr_model.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'modules') diff --git a/modules/ldsr_model.py b/modules/ldsr_model.py index 877e7e73..4d8687c2 100644 --- a/modules/ldsr_model.py +++ b/modules/ldsr_model.py @@ -22,6 +22,13 @@ class UpscalerLDSR(Upscaler): self.scalers = [scaler_data] def load_model(self, path: str): + # Remove incorrect project.yaml file if too big + yaml_path = os.path.join(self.model_path, "project.yaml") + if os.path.exists(yaml_path): + statinfo = os.stat(yaml_path) + if statinfo.st_size <= 10485760: + print("Removing invalid LDSR YAML file.") + os.remove(yaml_path) model = load_file_from_url(url=self.model_url, model_dir=self.model_path, file_name="model.pth", progress=True) yaml = load_file_from_url(url=self.yaml_url, model_dir=self.model_path, -- cgit v1.2.1 From 8d60645106d7e2daa0da89c5b21d7ffdac61cf9e Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 08:55:04 -0500 Subject: Fix model paths, ensure we have the right files. Also, clean up logging in the ldsr arch file. --- modules/ldsr_model.py | 9 +++++++-- modules/ldsr_model_arch.py | 3 +-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'modules') diff --git a/modules/ldsr_model.py b/modules/ldsr_model.py index 4d8687c2..7dff0a9c 100644 --- a/modules/ldsr_model.py +++ b/modules/ldsr_model.py @@ -24,13 +24,18 @@ class UpscalerLDSR(Upscaler): def load_model(self, path: str): # Remove incorrect project.yaml file if too big yaml_path = os.path.join(self.model_path, "project.yaml") + old_model_path = os.path.join(self.model_path, "model.pth") + new_model_path = os.path.join(self.model_path, "model.ckpt") if os.path.exists(yaml_path): statinfo = os.stat(yaml_path) - if statinfo.st_size <= 10485760: + if statinfo.st_size >= 10485760: print("Removing invalid LDSR YAML file.") os.remove(yaml_path) + if os.path.exists(old_model_path): + print("Renaming model from model.pth to model.ckpt") + os.rename(old_model_path, new_model_path) model = load_file_from_url(url=self.model_url, model_dir=self.model_path, - file_name="model.pth", progress=True) + file_name="model.ckpt", progress=True) yaml = load_file_from_url(url=self.yaml_url, model_dir=self.model_path, file_name="project.yaml", progress=True) diff --git a/modules/ldsr_model_arch.py b/modules/ldsr_model_arch.py index 7faac6e1..093a3210 100644 --- a/modules/ldsr_model_arch.py +++ b/modules/ldsr_model_arch.py @@ -100,7 +100,6 @@ class LDSR: # If we can adjust the max upscale size, then the 4 below should be our variable print("Foo") down_sample_rate = target_scale / 4 - print(f"Downsample rate is {down_sample_rate}") wd = width_og * down_sample_rate hd = height_og * down_sample_rate width_downsampled_pre = int(wd) @@ -111,7 +110,7 @@ class LDSR: f'Downsampling from [{width_og}, {height_og}] to [{width_downsampled_pre}, {height_downsampled_pre}]') im_og = im_og.resize((width_downsampled_pre, height_downsampled_pre), Image.LANCZOS) else: - print(f"Down sample rate is 1 from {target_scale} / 4") + print(f"Down sample rate is 1 from {target_scale} / 4 (Not downsampling)") logs = self.run(model["model"], im_og, diffusion_steps, eta) sample = logs["sample"] -- cgit v1.2.1 From 99aa132df7045077a420918d276fcca877fdc9e3 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 08:56:39 -0500 Subject: Remove useless print message --- modules/ldsr_model_arch.py | 1 - 1 file changed, 1 deletion(-) (limited to 'modules') diff --git a/modules/ldsr_model_arch.py b/modules/ldsr_model_arch.py index 093a3210..14db5076 100644 --- a/modules/ldsr_model_arch.py +++ b/modules/ldsr_model_arch.py @@ -98,7 +98,6 @@ class LDSR: im_og = image width_og, height_og = im_og.size # If we can adjust the max upscale size, then the 4 below should be our variable - print("Foo") down_sample_rate = target_scale / 4 wd = width_og * down_sample_rate hd = height_og * down_sample_rate -- cgit v1.2.1 From 19eb1467f1acbb45d3b416ad7887ba9ab8a94e75 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 09:05:00 -0500 Subject: Fix BSRGAN variable not found. --- modules/bsrgan_model.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/bsrgan_model.py b/modules/bsrgan_model.py index 77141545..339f402b 100644 --- a/modules/bsrgan_model.py +++ b/modules/bsrgan_model.py @@ -67,9 +67,8 @@ class UpscalerBSRGAN(modules.upscaler.Upscaler): else: filename = path if not os.path.exists(filename) or filename is None: - print("Unable to load %s from %s" % (self.model_dir, filename)) + print("Unable to load %s from %s" % (self.model_path, filename)) return None - print("Loading %s from %s" % (self.model_dir, filename)) model = RRDBNet(in_nc=3, out_nc=3, nf=64, nb=23, gc=32, sf=2) # define network model.load_state_dict(torch.load(filename), strict=True) model.eval() -- cgit v1.2.1 From ca87c09c0ec9f6d3fbfda5d8579907c7017eb629 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 09:28:28 -0500 Subject: Fix recursive model loading Ensure we find checkpoints within subdirectories. --- modules/modelloader.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/modelloader.py b/modules/modelloader.py index 1106aeb7..df29b6ef 100644 --- a/modules/modelloader.py +++ b/modules/modelloader.py @@ -1,3 +1,4 @@ +import glob import os import shutil import importlib @@ -41,7 +42,7 @@ 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): + for file in glob.iglob(place + '**/**', recursive=True): full_path = os.path.join(place, file) if os.path.isdir(full_path): continue @@ -50,6 +51,7 @@ def load_models(model_path: str, model_url: str = None, command_path: str = None if extension not in ext_filter: continue if file not in output: + print(f"FILE: {full_path}") output.append(full_path) if model_url is not None and len(output) == 0: -- cgit v1.2.1 From 5d52231bcb9fc21953b3d3495b577dc0bd82aa6a Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 09:28:48 -0500 Subject: Logging.... Cleanup. Sorry. --- modules/modelloader.py | 1 - 1 file changed, 1 deletion(-) (limited to 'modules') diff --git a/modules/modelloader.py b/modules/modelloader.py index df29b6ef..8c862b42 100644 --- a/modules/modelloader.py +++ b/modules/modelloader.py @@ -51,7 +51,6 @@ def load_models(model_path: str, model_url: str = None, command_path: str = None if extension not in ext_filter: continue if file not in output: - print(f"FILE: {full_path}") output.append(full_path) if model_url is not None and len(output) == 0: -- cgit v1.2.1 From f71d02b85feacf52d03d69d5caca97cd7d90b481 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 09:29:31 -0500 Subject: Remove unused LDSR opt --- modules/ldsr_model.py | 1 - 1 file changed, 1 deletion(-) (limited to 'modules') diff --git a/modules/ldsr_model.py b/modules/ldsr_model.py index 7dff0a9c..1c1070fc 100644 --- a/modules/ldsr_model.py +++ b/modules/ldsr_model.py @@ -53,5 +53,4 @@ class UpscalerLDSR(Upscaler): print("NO LDSR!") return img ddim_steps = shared.opts.ldsr_steps - pre_scale = shared.opts.ldsr_pre_down return ldsr.super_resolution(img, ddim_steps, self.scale) -- cgit v1.2.1 From 9fc1e49bd2674f8c30dd3545c1c271472ff6d3c2 Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 09:38:57 -0500 Subject: Set default value for ckpt-dir --- modules/shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/shared.py b/modules/shared.py index 8428c7a3..76233ea0 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -21,7 +21,7 @@ model_path = os.path.join(script_path, 'models') parser = argparse.ArgumentParser() parser.add_argument("--config", type=str, default=os.path.join(sd_path, "configs/stable-diffusion/v1-inference.yaml"), help="path to config which constructs model",) parser.add_argument("--ckpt", type=str, default=sd_model_file, help="path to checkpoint of stable diffusion model; this checkpoint will be added to the list of checkpoints and loaded by default if you don't have a checkpoint selected in settings",) -parser.add_argument("--ckpt-dir", type=str, default=None, help="Path to directory with stable diffusion checkpoints") +parser.add_argument("--ckpt-dir", type=str, default=os.path.join(model_path, "Stable-diffusion"), help="Path to directory with stable diffusion checkpoints") parser.add_argument("--gfpgan-dir", type=str, help="GFPGAN directory", default=('./src/gfpgan' if os.path.exists('./src/gfpgan') else './GFPGAN')) parser.add_argument("--gfpgan-model", type=str, help="GFPGAN model file name", default=None) parser.add_argument("--no-half", action='store_true', help="do not switch the model to 16-bit floats") -- cgit v1.2.1 From 8f1d412e7bcd279c3c49b0153def0e3d6d941e5a Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 12:51:54 -0500 Subject: Fix BSRGAN Model loading. --- modules/bsrgan_model.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/bsrgan_model.py b/modules/bsrgan_model.py index 339f402b..165f77b5 100644 --- a/modules/bsrgan_model.py +++ b/modules/bsrgan_model.py @@ -69,7 +69,8 @@ class UpscalerBSRGAN(modules.upscaler.Upscaler): if not os.path.exists(filename) or filename is None: print("Unable to load %s from %s" % (self.model_path, filename)) return None - model = RRDBNet(in_nc=3, out_nc=3, nf=64, nb=23, gc=32, sf=2) # define network + print("Loading %s from %s" % (self.model_path, filename)) + model = RRDBNet(in_nc=3, out_nc=3, nf=64, nb=23, gc=32, sf=4) # define network model.load_state_dict(torch.load(filename), strict=True) model.eval() for k, v in model.named_parameters(): -- cgit v1.2.1 From 7ab91d9e1bf3abc11dc0d90e270b199ae8c3c84a Mon Sep 17 00:00:00 2001 From: d8ahazard Date: Fri, 30 Sep 2022 13:29:33 -0500 Subject: Update bsrgan_model.py --- modules/bsrgan_model.py | 1 - 1 file changed, 1 deletion(-) (limited to 'modules') diff --git a/modules/bsrgan_model.py b/modules/bsrgan_model.py index 827a50a5..e62c6657 100644 --- a/modules/bsrgan_model.py +++ b/modules/bsrgan_model.py @@ -69,7 +69,6 @@ class UpscalerBSRGAN(modules.upscaler.Upscaler): if not os.path.exists(filename) or filename is None: print(f"BSRGAN: Unable to load model from {filename}", file=sys.stderr) return None - print("Loading %s from %s" % (self.model_path, filename)) model = RRDBNet(in_nc=3, out_nc=3, nf=64, nb=23, gc=32, sf=4) # define network model.load_state_dict(torch.load(filename), strict=True) model.eval() -- cgit v1.2.1