aboutsummaryrefslogtreecommitdiffstats
path: root/modules/ldsr_model_arch.py
diff options
context:
space:
mode:
authorAUTOMATIC1111 <16777216c@gmail.com>2022-11-06 08:27:54 +0000
committerGitHub <noreply@github.com>2022-11-06 08:27:54 +0000
commit07d1bd426722b4c53b38ff682c5aab53177d8530 (patch)
tree4fdad803a4536cec2bd3e622c5f4cfb980f04550 /modules/ldsr_model_arch.py
parent3f3d14afd5abd07d3843370dc1c28be299dbdbab (diff)
parent6e4de5b4422dfc0d45063b2c8c78b19f00321615 (diff)
downloadstable-diffusion-webui-gfx803-07d1bd426722b4c53b38ff682c5aab53177d8530.tar.gz
stable-diffusion-webui-gfx803-07d1bd426722b4c53b38ff682c5aab53177d8530.tar.bz2
stable-diffusion-webui-gfx803-07d1bd426722b4c53b38ff682c5aab53177d8530.zip
Merge branch 'master' into roy.add_simple_interrogate_api
Diffstat (limited to 'modules/ldsr_model_arch.py')
-rw-r--r--modules/ldsr_model_arch.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/modules/ldsr_model_arch.py b/modules/ldsr_model_arch.py
index 14db5076..90e0a2f0 100644
--- a/modules/ldsr_model_arch.py
+++ b/modules/ldsr_model_arch.py
@@ -101,8 +101,8 @@ class LDSR:
down_sample_rate = target_scale / 4
wd = width_og * down_sample_rate
hd = height_og * down_sample_rate
- width_downsampled_pre = int(wd)
- height_downsampled_pre = int(hd)
+ width_downsampled_pre = int(np.ceil(wd))
+ height_downsampled_pre = int(np.ceil(hd))
if down_sample_rate != 1:
print(
@@ -110,7 +110,12 @@ class LDSR:
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 (Not downsampling)")
- logs = self.run(model["model"], im_og, diffusion_steps, eta)
+
+ # pad width and height to multiples of 64, pads with the edge values of image to avoid artifacts
+ pad_w, pad_h = np.max(((2, 2), np.ceil(np.array(im_og.size) / 64).astype(int)), axis=0) * 64 - im_og.size
+ im_padded = Image.fromarray(np.pad(np.array(im_og), ((0, pad_h), (0, pad_w), (0, 0)), mode='edge'))
+
+ logs = self.run(model["model"], im_padded, diffusion_steps, eta)
sample = logs["sample"]
sample = sample.detach().cpu()
@@ -120,6 +125,9 @@ class LDSR:
sample = np.transpose(sample, (0, 2, 3, 1))
a = Image.fromarray(sample[0])
+ # remove padding
+ a = a.crop((0, 0) + tuple(np.array(im_og.size) * 4))
+
del model
gc.collect()
torch.cuda.empty_cache()