Skip to content

Commit 7101c73

Browse files
authored
[StableDiffusionimg2img] validating input type (huggingface#1913)
* [StableDiffusionimg2img] validating input type * fixing tests * running make style * make fix-copies
1 parent f6f4176 commit 7101c73

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py

+5
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,11 @@ def get_timesteps(self, num_inference_steps, strength, device):
424424
return timesteps, num_inference_steps - t_start
425425

426426
def prepare_latents(self, image, timestep, batch_size, num_images_per_prompt, dtype, device, generator=None):
427+
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
428+
raise ValueError(
429+
f"`image` has to be of type `torch.Tensor`, `PIL.Image.Image` or list but is {type(image)}"
430+
)
431+
427432
image = image.to(device=device, dtype=dtype)
428433

429434
batch_size = batch_size * num_images_per_prompt

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_depth2img.py

+5
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ def get_timesteps(self, num_inference_steps, strength, device):
343343

344344
# Copied from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_img2img.StableDiffusionImg2ImgPipeline.prepare_latents
345345
def prepare_latents(self, image, timestep, batch_size, num_images_per_prompt, dtype, device, generator=None):
346+
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
347+
raise ValueError(
348+
f"`image` has to be of type `torch.Tensor`, `PIL.Image.Image` or list but is {type(image)}"
349+
)
350+
346351
image = image.to(device=device, dtype=dtype)
347352

348353
batch_size = batch_size * num_images_per_prompt

src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py

+5
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,11 @@ def get_timesteps(self, num_inference_steps, strength, device):
434434
return timesteps, num_inference_steps - t_start
435435

436436
def prepare_latents(self, image, timestep, batch_size, num_images_per_prompt, dtype, device, generator=None):
437+
if not isinstance(image, (torch.Tensor, PIL.Image.Image, list)):
438+
raise ValueError(
439+
f"`image` has to be of type `torch.Tensor`, `PIL.Image.Image` or list but is {type(image)}"
440+
)
441+
437442
image = image.to(device=device, dtype=dtype)
438443

439444
batch_size = batch_size * num_images_per_prompt

0 commit comments

Comments
 (0)