image-segmentation: AttributeError: read
Author: andysingal
Pull request: no
Labels: name: Core: Pipeline

name: Vision

### System Info

```
2024-04-25 02:49:06.163075: E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc:9261] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2024-04-25 02:49:06.163144: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:607] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2024-04-25 02:49:06.164924: E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc:1515] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2024-04-25 02:49:08.255740: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
WARNING:tensorflow:From /usr/local/lib/python3.10/dist-packages/transformers/commands/env.py:100: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2024-04-25 02:49:12.135072: W tensorflow/core/common_runtime/gpu/gpu_bfc_allocator.cc:47] Overriding orig_value setting because the TF_FORCE_GPU_ALLOW_GROWTH environment variable is set. Original config value was 0.

Copy-and-paste the text below in your GitHub issue and FILL OUT the two last points.

- `transformers` version: 4.40.1
- Platform: Linux-6.1.58+-x86_64-with-glibc2.35
- Python version: 3.10.12
- Huggingface_hub version: 0.22.2
- Safetensors version: 0.4.3
- Accelerate version: 0.29.3
- Accelerate config: 	not found
- PyTorch version (GPU?): 2.2.1+cu121 (True)
- Tensorflow version (GPU?): 2.15.0 (True)
- Flax version (CPU?/GPU?/TPU?): 0.8.2 (gpu)
- Jax version: 0.4.26
- JaxLib version: 0.4.26
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

```

### Who can help?

@amy

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

```
panoptic_segmentation = pipeline("image-segmentation", "facebook/mask2former-swin-large-cityscapes-panoptic")
results = panoptic_segmentation(Image.open(image))
results
```

ERROR


<img width="1053" alt="Screenshot 2024-04-25 at 8 20 32 AM" src="https://github.com/huggingface/transformers/assets/20493493/ddc1666c-bcb9-4bfa-b850-1a875508ff07">



### Expected behavior

display segmented images 

Comments:
Hi @andysingal - can you share the image? It looks like an issue with the Pillow library reading it, rather than something related to the pipeline i.e. if you did: 

```py
from PIL import Image

image = # ???? 
opened_image = Image.open(image)
```

I'd expect you'd see the same error 

Image from the documentation - image segmentation

On Thu, Apr 25, 2024 at 15:18 amyeroberts ***@***.***> wrote:

> Hi @andysingal <https://github.com/andysingal> - can you share the image?
> It looks like an issue with the Pillow library reading it, rather than
> something related to the pipeline i.e. if you did:
>
> from PIL import Image
> image = # ???? opened_image = Image.open(image)
>
> I'd expect you'd see the same error
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/transformers/issues/30467#issuecomment-2076793922>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AE4LJNKRKKABY4LDOXDAFS3Y7DGQDAVCNFSM6AAAAABGYALUSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZWG44TGOJSGI>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


OK - it's because `image` is already a PIL.Image.Image. I've opened a PR to address. In the meantime, you can do: 

```
results = panoptic_segmentation(image)
```