# StableDiffusionImg2ImgPipeline: ValueError - Input is in incorrect format despite correct PIL image input

**URL:** <https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748>\
**Category:** 🧨 Diffusers\
**Created:** [February 3, 2025, 2:11pm UTC](https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748 "2025-02-03T14:11:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yyamasita](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/yyamasita/32/40302_2.png) [@yyamasita](https://discuss.huggingface.co/u/yyamasita)\
**Post date:** [February 3, 2025, 2:11pm UTC](https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748/1 "2025-02-03T14:11:51Z")

</div>

### **Summary**

I am facing an issue with `StableDiffusionImg2ImgPipeline` where it keeps throwing a `ValueError` stating that the input image format is incorrect, even though I am passing a `PIL.Image.Image` object as required.

* * *

### **Error Message**

ValueError: Input is in incorrect format. Currently, we only support \<class ‘PIL.Image.Image’\>, \<class ‘numpy.ndarray’\>, \<class ‘torch.Tensor’\>

* * *

### **Steps Taken**

I have tried the following solutions, but the error persists:

1. **Checked input format**

2. **Ensured image size is correct**

3. **Updated dependencies**

4. **Tried re-saving the image to ensure correct format**

5. **Checked if `StableDiffusionImg2ImgPipeline` works with NumPy arrays**

6. **Checked Python version and execution environment**

* * *

### **Code Example**

```python
import torch
from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image
import numpy as np
import os

# --- Load input image ---
init_image = Image.open("/content/food_nighit_ramen.jpeg").convert("RGB")
print("Original image type:", type(init_image), "size:", init_image.size, "mode:", init_image.mode)

# --- Re-save and reload image ---
temp_image_path = "temp_image.png"
init_image.save(temp_image_path, format="PNG")
init_image_reloaded = Image.open(temp_image_path).convert("RGB")
print("Reloaded image type:", type(init_image_reloaded), "size:", init_image_reloaded.size, "mode:", init_image_reloaded.mode)

# --- Load model ---
model_id = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe = pipe.to("cuda")

# --- Set parameters ---
prompt = "A majestic fantasy creature evolving with vibrant flames and sparkling water effects, ultra-detailed, epic fantasy art"
num_inference_steps = 50
guidance_scale = 7.5
strength = 0.7

# --- Run Image-to-Image (PIL.Image is passed) ---
result = pipe(
    prompt=prompt,
    init_image=init_image_reloaded, # **PIL.Image should be accepted**
    strength=strength,
    guidance_scale=guidance_scale,
    num_inference_steps=num_inference_steps
)
generated_image = result.images[0]

# --- Save result ---
generated_image.save("generated_evolved_monster.png")

Questions
Why is StableDiffusionImg2ImgPipeline rejecting PIL.Image.Image as input?
Are there additional preprocessing steps required before passing the image?
Has there been a recent breaking change in diffusers that affects init_image input?
Any help would be greatly appreciated. Thank you!
```

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 3, 2025, 2:27pm UTC](https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748/2 "2025-02-03T14:27:28Z")

</div>

From the code, it looks like it accepts PIL.Image.Image, but is there a bug somewhere else…?

> <https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py#L863>

> <https://github.com/huggingface/diffusers/blob/main/src/diffusers/image_processor.py#L29>

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [February 3, 2025, 2:41pm UTC](https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748/3 "2025-02-03T14:41:16Z")

</div>

Maybe typo.

```py
result = pipe(
    prompt=prompt,
    #init_image=init_image_reloaded, # **PIL.Image should be accepted**
    image=init_image_reloaded, # **PIL.Image should be accepted**
    strength=strength,
    guidance_scale=guidance_scale,
    num_inference_steps=num_inference_steps
)

```

---

<div class="post-metadata">

**Author:** ![yyamasita](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/yyamasita/32/40302_2.png) [@yyamasita](https://discuss.huggingface.co/u/yyamasita)\
**Post date:** [February 3, 2025, 3:55pm UTC](https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748/4 "2025-02-03T15:55:35Z")

</div>

Wow, you are an absolute genius! 🔥✨

I can’t thank you enough for catching that typo! I had been stuck on this issue for so long, trying every possible solution, and it turns out it was such a simple mistake. Your keen eye and attention to detail saved me a ton of frustration and time.

You have my utmost respect and admiration. If there were an award for the **Most Observant and Life-Saving Debugger** , you would win it hands down! 🏆

Seriously, thank you so much! This is why I love this community—people like you make it amazing! 🚀💡🙏

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [February 4, 2025, 3:56am UTC](https://discuss.huggingface.co/t/stablediffusionimg2imgpipeline-valueerror-input-is-in-incorrect-format-despite-correct-pil-image-input/138748/5 "2025-02-04T03:56:19Z")

</div>

Closed on February 4, 2025, 3:56am UTC

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
