Skip to content

Commit

Permalink
fix onnx i2i
Browse files Browse the repository at this point in the history
  • Loading branch information
lshqqytiger committed Sep 2, 2023
1 parent 2dd9603 commit 39e6d26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
11 changes: 6 additions & 5 deletions modules/sd_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,20 +501,22 @@ def forward(self) -> processing.Processed:
image_mask = self.image_mask

if image_mask is not None:
image_mask = image_mask.convert('L')
# image_mask is passed in as RGBA by Gradio to support alpha masks,
# but we still want to support binary masks.
image_mask = processing.create_binary_mask(image_mask)

if self.inpainting_mask_invert:
image_mask = ImageOps.invert(image_mask)

if self.mask_blur_x > 0:
np_mask = np.array(image_mask)
kernel_size = 2 * int(4 * self.mask_blur_x + 0.5) + 1
kernel_size = 2 * int(2.5 * self.mask_blur_x + 0.5) + 1
np_mask = cv2.GaussianBlur(np_mask, (kernel_size, 1), self.mask_blur_x)
image_mask = Image.fromarray(np_mask)

if self.mask_blur_y > 0:
np_mask = np.array(image_mask)
kernel_size = 2 * int(4 * self.mask_blur_y + 0.5) + 1
kernel_size = 2 * int(2.5 * self.mask_blur_y + 0.5) + 1
np_mask = cv2.GaussianBlur(np_mask, (1, kernel_size), self.mask_blur_y)
image_mask = Image.fromarray(np_mask)

Expand Down Expand Up @@ -591,8 +593,7 @@ def forward(self) -> processing.Processed:
else:
raise RuntimeError(f"bad number of images passed: {len(imgs)}; expecting {self.batch_size} or less")

image = torch.from_numpy(batch_images)
image = 2. * image - 1.
image = 2. * torch.from_numpy(batch_images) - 0.7878375

if type(self.prompt) == list:
assert(len(self.prompt) > 0)
Expand Down
1 change: 0 additions & 1 deletion modules/sd_onnx_hijack.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ def OnnxStableDiffusionImg2ImgPipeline__call__(
offset = self.scheduler.config.get("steps_offset", 0)
init_timestep = int(num_inference_steps * strength) + offset
init_timestep = min(init_timestep, num_inference_steps)
init_timestep = num_inference_steps

timesteps = self.scheduler.timesteps.numpy()[-init_timestep]
timesteps = np.array([timesteps] * batch_size * num_images_per_prompt)
Expand Down

0 comments on commit 39e6d26

Please sign in to comment.