From f9c0046897e49d2fcc9b8d6c79c2c3d82fc365bc Mon Sep 17 00:00:00 2001 From: deggua <26562606+deggua@users.noreply.github.com> Date: Fri, 2 Sep 2022 07:18:12 -0400 Subject: [PATCH 1/3] Fix for fill latent zeros/noise in masking mode --- webui.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webui.py b/webui.py index 8901706d..f4fcb879 100644 --- a/webui.py +++ b/webui.py @@ -1573,6 +1573,12 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): self.mask = torch.asarray(1.0 - latmask).to(device).type(sd_model.dtype) self.nmask = torch.asarray(latmask).to(device).type(sd_model.dtype) + if self.mask is not None: + if self.inpainting_fill == 2: + self.init_latent = self.init_latent * self.mask + create_random_tensors(self.init_latent.shape[1:], [self.seed + x + 1 for x in range(self.init_latent.shape[0])]) * self.nmask + elif self.inpainting_fill == 3: + self.init_latent = self.init_latent * self.mask + def sample(self, x, conditioning, unconditional_conditioning): if self.mask is not None: From 422981c85b9300a55787341df8778841bedf748a Mon Sep 17 00:00:00 2001 From: deggua <26562606+deggua@users.noreply.github.com> Date: Fri, 2 Sep 2022 07:28:39 -0400 Subject: [PATCH 2/3] Forgot to remove the broken lines --- webui.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/webui.py b/webui.py index f4fcb879..2c15be2f 100644 --- a/webui.py +++ b/webui.py @@ -1580,13 +1580,6 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): self.init_latent = self.init_latent * self.mask def sample(self, x, conditioning, unconditional_conditioning): - - if self.mask is not None: - if self.inpainting_fill == 2: - x = x * self.mask + create_random_tensors(x.shape[1:], [self.seed + x + 1 for x in range(x.shape[0])]) * self.nmask - elif self.inpainting_fill == 3: - x = x * self.mask - samples = self.sampler.sample_img2img(self, self.init_latent, x, conditioning, unconditional_conditioning) if self.mask is not None: From 4e2cc78e5241f15f7550eab08d62720252f3397b Mon Sep 17 00:00:00 2001 From: deggua <26562606+deggua@users.noreply.github.com> Date: Fri, 2 Sep 2022 07:41:10 -0400 Subject: [PATCH 3/3] Removed unnecessary condition check for masking --- webui.py | 1 - 1 file changed, 1 deletion(-) diff --git a/webui.py b/webui.py index 2c15be2f..c1af452f 100644 --- a/webui.py +++ b/webui.py @@ -1573,7 +1573,6 @@ class StableDiffusionProcessingImg2Img(StableDiffusionProcessing): self.mask = torch.asarray(1.0 - latmask).to(device).type(sd_model.dtype) self.nmask = torch.asarray(latmask).to(device).type(sd_model.dtype) - if self.mask is not None: if self.inpainting_fill == 2: self.init_latent = self.init_latent * self.mask + create_random_tensors(self.init_latent.shape[1:], [self.seed + x + 1 for x in range(self.init_latent.shape[0])]) * self.nmask elif self.inpainting_fill == 3: