Skip to content

Commit cd87884

Browse files
[Stable Diffusion Inpaint & ControlNet inpaint] Correct timestep inpaint (#3749)
* Correct timestep inpaint * make style * Fix * Apply suggestions from code review * make style
1 parent 07c8c37 commit cd87884

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

src/diffusers/pipelines/controlnet/pipeline_controlnet.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ def check_image(self, image, prompt, prompt_embeds):
611611
and not image_is_np_list
612612
):
613613
raise TypeError(
614-
"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors"
614+
f"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors, but is {type(image)}"
615615
)
616616

617617
if image_is_pil:

src/diffusers/pipelines/controlnet/pipeline_controlnet_img2img.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ def check_image(self, image, prompt, prompt_embeds):
638638
and not image_is_np_list
639639
):
640640
raise TypeError(
641-
"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors"
641+
f"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors, but is {type(image)}"
642642
)
643643

644644
if image_is_pil:

src/diffusers/pipelines/controlnet/pipeline_controlnet_inpaint.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ def check_image(self, image, prompt, prompt_embeds):
770770
and not image_is_np_list
771771
):
772772
raise TypeError(
773-
"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors"
773+
f"image must be passed and be one of PIL image, numpy array, torch tensor, list of PIL images, list of numpy arrays or list of torch tensors, but is {type(image)}"
774774
)
775775

776776
if image_is_pil:
@@ -1306,7 +1306,10 @@ def __call__(
13061306
init_mask = mask[:1]
13071307

13081308
if i < len(timesteps) - 1:
1309-
init_latents_proper = self.scheduler.add_noise(init_latents_proper, noise, torch.tensor([t]))
1309+
noise_timestep = timesteps[i + 1]
1310+
init_latents_proper = self.scheduler.add_noise(
1311+
init_latents_proper, noise, torch.tensor([noise_timestep])
1312+
)
13101313

13111314
latents = (1 - init_mask) * init_latents_proper + init_mask * latents
13121315

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,10 @@ def __call__(
10381038
init_mask = mask[:1]
10391039

10401040
if i < len(timesteps) - 1:
1041-
init_latents_proper = self.scheduler.add_noise(init_latents_proper, noise, torch.tensor([t]))
1041+
noise_timestep = timesteps[i + 1]
1042+
init_latents_proper = self.scheduler.add_noise(
1043+
init_latents_proper, noise, torch.tensor([noise_timestep])
1044+
)
10421045

10431046
latents = (1 - init_mask) * init_latents_proper + init_mask * latents
10441047

0 commit comments

Comments
 (0)