From 3b47eb3b07b0bc17ac9ad04a9ccf062c1fdfe285 Mon Sep 17 00:00:00 2001 From: cmdr2 Date: Wed, 14 Sep 2022 11:36:55 +0530 Subject: [PATCH] Bug fix - tasks with an initial image were not resizing the initial image to the desired dimension --- ui/sd_internal/runtime.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ui/sd_internal/runtime.py b/ui/sd_internal/runtime.py index 75163ec3..0fe21ee6 100644 --- a/ui/sd_internal/runtime.py +++ b/ui/sd_internal/runtime.py @@ -273,7 +273,7 @@ def mk_img(req: Request): else: handler = _img2img - init_image = load_img(req.init_image) + init_image = load_img(req.init_image, opt_W, opt_H) init_image = init_image.to(device) if device != "cpu" and precision == "autocast": @@ -511,12 +511,15 @@ def load_model_from_config(ckpt, verbose=False): class UserInitiatedStop(Exception): pass -def load_img(img_str): +def load_img(img_str, w0, h0): image = base64_str_to_img(img_str).convert("RGB") w, h = image.size print(f"loaded input image of size ({w}, {h}) from base64") + if h0 is not None and w0 is not None: + h, w = h0, w0 + w, h = map(lambda x: x - x % 64, (w, h)) # resize to integer multiple of 64 - image = image.resize((w, h), resample=Image.LANCZOS) + image = image.resize((w, h), resample=Image.Resampling.LANCZOS) image = np.array(image).astype(np.float32) / 255.0 image = image[None].transpose(0, 3, 1, 2) image = torch.from_numpy(image)