# Invalid image format

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Finvalid-image-format%2F112175%3E%5C
**Category:** Intermediate\
**Created:** [October 15, 2024, 10:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Finvalid-image-format%2F112175 "2024-10-15T10:40:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ammarfunprime](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@ammarfunprime](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fammarfunprime)%5C
**Post date:** [October 15, 2024, 10:40am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Finvalid-image-format%2F112175%2F1 "2024-10-15T10:40:08Z")

</div>

I’m encountering a persistent issue when running the `StableDiffusionInpaintPipeline` for an inpainting task. Despite passing inputs in the expected formats (both the image and mask are in `PIL.Image.Image` format with correct sizes), I keep receiving the following error:

```auto
ValueError: Input is in incorrect format. Currently, we only support <class 'PIL.Image.Image'>, <class 'numpy.ndarray'>, <class 'torch.Tensor'>

```

Here’s the code that triggers the error:

```auto
# Image and mask setup
image_pil = Image.fromarray(image_np)
mask_pil = Image.fromarray(black_mask).convert("L")

# Generator for reproducibility
generator = torch.Generator(device="cuda").manual_seed(0)

image = model["pipeline"](
    prompt=prompt,
    negative_prompt=IMG_INPAINTING_NEG_PROMPT,
    image=image_pil, # PIL Image
    mask=mask_pil, # Grayscale mask (mode "L")
    guidance_scale=8.0,
    num_inference_steps=50,
    generator=generator,
).images[0]

```

Image and Mask Details:

- **Image size** : `(512, 768)`, mode: `RGB`
- **Mask size** : `(512, 768)`, mode: `L`
- The mask is binary (contains only 0 and 255 values).

I’ve also tried using a simple manually created mask to ensure that FastSAM-generated masks aren’t causing the issue, but I still get the same error.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [October 15, 2024, 10:59am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Finvalid-image-format%2F112175%2F2 "2024-10-15T10:59:53Z")

</div>

It looks like you are stuck here, but I think this is a bug in Diffusers…?

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

```py
def is_valid_image(image):
    return isinstance(image, PIL.Image.Image) or isinstance(image, (np.ndarray, torch.Tensor)) and image.ndim in (2, 3)

```

Maybe this is correct.

```py
def is_valid_image(image):
    return isinstance(image, PIL.Image.Image) or (isinstance(image, (np.ndarray, torch.Tensor)) and image.ndim in (2, 3))

```

`ndim` is not an element of `PIL.Image.Image`.

> <https://github.com/python-pillow/Pillow/blob/main/src/PIL/Image.py>

Currently, it should be possible to slip through this check by passing it in numpy format.

@sayakpaul I found a crappy bug in Diffusers.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [October 29, 2024, 11:48am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Finvalid-image-format%2F112175%2F3 "2024-10-29T11:48:45Z")

</div>

I opened PR on github.

> <https://github.com/huggingface/diffusers/pull/9795>
>
> \`PIL.Image.Image\` doesn't have \`dim\`.
> 
> See:
> /static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F%E2%80%A6invalid-image-format%2F112175
> 
> \# What does this PR do?
> 
> \<!--
> Congratulations! You've made it this far! You're not quite done yet though.
> 
> Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.
> 
> Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.
> 
> Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
> \--\>
> 
> 
> 
> Fixes # (issue)
> 
> 
> \## Before submitting
> \- \[x\] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
> \- \[x\] Did you read the \[contributor guideline\](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md)?
> \- \[x\] Did you read our \[philosophy doc\](https://github.com/huggingface/diffusers/blob/main/PHILOSOPHY.md) (important for complex PRs)?
> \- \[\] Was this discussed/approved via a GitHub issue or the \[forum\](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fc%2Fdiscussion-related-to-httpsgithubcomhuggingfacediffusers%2F63)%3F Please add a link to it if that's the case.
> \- \[\] Did you make sure to update the documentation with your changes? Here are the
> \[documentation guidelines\](https://github.com/huggingface/diffusers/tree/main/docs), and
> \[here are tips on formatting docstrings\](https://github.com/huggingface/diffusers/tree/main/docs#writing-source-documentation).
> \- \[\] Did you write any new necessary tests?
> 
> 
> \## Who can review?
> 
> Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
> members/contributors who may be interested in your PR.
> 
> \<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @.
> 
> If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of \*\*who to tag\*\*.
> Please tag fewer than 3 people.
> 
> Core library:
> 
> \- Schedulers: @yiyixuxu
> \- Pipelines and pipeline callbacks: @yiyixuxu and @asomoza
> \- Training examples: @sayakpaul
> \- Docs: @stevhliu and @sayakpaul
> \- JAX and MPS: @pcuenca
> \- Audio: @sanchit-gandhi
> \- General functionalities: @sayakpaul @yiyixuxu @DN6
> 
> Integrations:
> 
> \- deepspeed: HF Trainer/Accelerate: @SunMarc
> \- PEFT: @sayakpaul @BenjaminBossan
> 
> HF projects:
> 
> \- accelerate: \[different repo\](https://github.com/huggingface/accelerate)
> \- datasets: \[different repo\](https://github.com/huggingface/datasets)
> \- transformers: \[different repo\](https://github.com/huggingface/transformers)
> \- safetensors: \[different repo\](https://github.com/huggingface/safetensors)
> 
> \--\>
