Unverified Commit 2f489571 authored by Laveraaa's avatar Laveraaa Committed by GitHub
Browse files

Update pipeline_stable_diffusion_inpaint_legacy.py resize to integer multiple...

Update pipeline_stable_diffusion_inpaint_legacy.py resize to integer multiple of 8 instead of 32 for init image and mask (#2350)

Update pipeline_stable_diffusion_inpaint_legacy.py

Change resize to integer multiple of 8 instead of 32
parent e75eae37
...@@ -42,7 +42,7 @@ logger = logging.get_logger(__name__) ...@@ -42,7 +42,7 @@ logger = logging.get_logger(__name__)
def preprocess_image(image): def preprocess_image(image):
w, h = image.size w, h = image.size
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32 w, h = map(lambda x: x - x % 8, (w, h)) # resize to integer multiple of 8
image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"]) image = image.resize((w, h), resample=PIL_INTERPOLATION["lanczos"])
image = np.array(image).astype(np.float32) / 255.0 image = np.array(image).astype(np.float32) / 255.0
image = image[None].transpose(0, 3, 1, 2) image = image[None].transpose(0, 3, 1, 2)
...@@ -54,7 +54,7 @@ def preprocess_mask(mask, scale_factor=8): ...@@ -54,7 +54,7 @@ def preprocess_mask(mask, scale_factor=8):
if not isinstance(mask, torch.FloatTensor): if not isinstance(mask, torch.FloatTensor):
mask = mask.convert("L") mask = mask.convert("L")
w, h = mask.size w, h = mask.size
w, h = map(lambda x: x - x % 32, (w, h)) # resize to integer multiple of 32 w, h = map(lambda x: x - x % 8, (w, h)) # resize to integer multiple of 8
mask = mask.resize((w // scale_factor, h // scale_factor), resample=PIL_INTERPOLATION["nearest"]) mask = mask.resize((w // scale_factor, h // scale_factor), resample=PIL_INTERPOLATION["nearest"])
mask = np.array(mask).astype(np.float32) / 255.0 mask = np.array(mask).astype(np.float32) / 255.0
mask = np.tile(mask, (4, 1, 1)) mask = np.tile(mask, (4, 1, 1))
...@@ -76,7 +76,7 @@ def preprocess_mask(mask, scale_factor=8): ...@@ -76,7 +76,7 @@ def preprocess_mask(mask, scale_factor=8):
# (potentially) reduce mask channel dimension from 3 to 1 for broadcasting to latent shape # (potentially) reduce mask channel dimension from 3 to 1 for broadcasting to latent shape
mask = mask.mean(dim=1, keepdim=True) mask = mask.mean(dim=1, keepdim=True)
h, w = mask.shape[-2:] h, w = mask.shape[-2:]
h, w = map(lambda x: x - x % 32, (h, w)) # resize to integer multiple of 32 h, w = map(lambda x: x - x % 8, (h, w)) # resize to integer multiple of 8
mask = torch.nn.functional.interpolate(mask, (h // scale_factor, w // scale_factor)) mask = torch.nn.functional.interpolate(mask, (h // scale_factor, w // scale_factor))
return mask return mask
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment