Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def preprocess_mask(mask):
mask = np.array(mask).astype(np.float32) / 255.0
mask = np.tile(mask, (4, 1, 1))
mask = mask[None].transpose(0, 1, 2, 3) # what does this step do?
# make sure mask is properly valid
mask[mask < 0.5] = 0.0
mask[mask >= 0.5] = 1.0
mask = 1 - mask # repaint white, keep black
mask = torch.from_numpy(mask)
return mask
Expand Down Expand Up @@ -66,7 +69,7 @@ def __call__(
prompt: Union[str, List[str]],
init_image: Union[torch.FloatTensor, PIL.Image.Image],
mask_image: Union[torch.FloatTensor, PIL.Image.Image],
strength: float = 0.8,
strength: float = 1.0,
num_inference_steps: Optional[int] = 50,
guidance_scale: Optional[float] = 7.5,
eta: Optional[float] = 0.0,
Expand Down Expand Up @@ -177,8 +180,12 @@ def __call__(
latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs)["prev_sample"]

# masking
init_latents_proper = self.scheduler.add_noise(init_latents_orig, noise, t)
latents = (init_latents_proper * mask) + (latents * (1 - mask))
if t > 1:
t_noise = torch.randn(latents.shape, generator=generator, device=self.device)
init_latents_proper = self.scheduler.add_noise(init_latents_orig, t_noise, t-1)
latents = init_latents_proper * mask + latents * (1-mask)
else:
latents = init_latents_orig * mask + latents * (1-mask)

# scale and decode the image latents with vae
latents = 1 / 0.18215 * latents
Expand Down
Loading