# ViTImageProcessor output visualization

**URL:** <https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335>\
**Category:** 🤗Tokenizers\
**Created:** [March 7, 2024, 6:59am UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335 "2024-03-07T06:59:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sushmitaupadhyay](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sushmitaupadhyay](https://discuss.huggingface.co/u/Sushmitaupadhyay)\
**Post date:** [March 7, 2024, 6:59am UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/1 "2024-03-07T06:59:51Z")

</div>

when I am printing the output of ViTImageprocessor using Matplotlib I can see the same image is reduces in size and repeated 6 times in a frame of 224x224 with different contrast and intensity.  
If I have understood correctly, ViT divides the image into patches. So the entire image should have been divided into small patches of size 16x16. But the result is not like that.  
What is the issue here?

---

<div class="post-metadata">

**Author:** ![Sandy1857](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sandy1857](https://discuss.huggingface.co/u/Sandy1857)\
**Post date:** [March 8, 2024, 7:22pm UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/2 "2024-03-08T19:22:34Z")

</div>

ViT takes in an input of resolution 224x224. The ViTImageProcessor just handles the resizing and normalisation of the image to that of the correct resolution.

The patches of 16x16 that you mentioned are taken over this processed image which the Vit model then consumes.

And additionally, if a an RGB image is what you gave to the ViTImageProcessor, an RGB image is what you must get with just sizes of 224x224 and 3 channels. Don’t know how you got 6 channel image.

---

<div class="post-metadata">

**Author:** ![Sushmitaupadhyay](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sushmitaupadhyay](https://discuss.huggingface.co/u/Sushmitaupadhyay)\
**Post date:** [March 12, 2024, 5:58am UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/3 "2024-03-12T05:58:31Z")

</div>

This is my input image  
 ![output](https://us1.discourse-cdn.com/hellohellohello/original/3X/f/f/ff2c9ed41df9cf8058671c4922021b377d9d8beb.png)

---

<div class="post-metadata">

**Author:** ![Sushmitaupadhyay](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sushmitaupadhyay](https://discuss.huggingface.co/u/Sushmitaupadhyay)\
**Post date:** [March 12, 2024, 6:00am UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/4 "2024-03-12T06:00:18Z")

</div>

This is my output after passing it through the ViTImageProcessor  
 ![output1](https://us1.discourse-cdn.com/hellohellohello/original/3X/4/9/494b67d33fbe8ecdfb65c6b0db619c7b6d525712.png)  
I am visualising the processed image using matplotlib. Is that the issue?

---

<div class="post-metadata">

**Author:** ![Sandy1857](https://avatars.discourse-cdn.com/v4/letter/s/ecae2f/32.png) [@Sandy1857](https://discuss.huggingface.co/u/Sandy1857)\
**Post date:** [March 12, 2024, 4:57pm UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/5 "2024-03-12T16:57:11Z")

</div>

I don’t know what code you ran, but could you just post the output pixel\_values after passing the image through ViTImageProcessor, removing/unsqeezing it’s batch dimension, and then get the image using PIL Image.fromarray function?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](https://discuss.huggingface.co/u/nielsr)\
**Post date:** [March 12, 2024, 7:48pm UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/6 "2024-03-12T19:48:40Z")

</div>

Hi,

Here’s how you can visualize the output of ViTImageProcessor:

```auto
from transformers import ViTImageProcessor
import requests
from PIL import Image

image_processor = ViTImageProcessor()

url = 'http://images.cocodataset.org/val2017/000000039769.jpg'
image = Image.open(requests.get(url, stream=True).raw)

pixel_values = image_processor(image, return_tensors="pt").pixel_values

# denormalize the pixel values for visualization purposes
mean = image_processor.image_mean
std = image_processor.image_std

unnormalized_image = (pixel_values[0].numpy() * np.array(std)[:, None, None]) + np.array(mean)[:, None, None]
unnormalized_image = (unnormalized_image * 255).astype(np.uint8)
unnormalized_image = np.moveaxis(unnormalized_image, 0, -1)
unnormalized_image = Image.fromarray(unnormalized_image)

```

which gives me this:  
 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/c/5/c56599ba84e9fb694caf10d9f0eb23af1a352361.jpeg)

This is a 224x224 image.

---

<div class="post-metadata">

**Author:** ![Sushmitaupadhyay](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sushmitaupadhyay](https://discuss.huggingface.co/u/Sushmitaupadhyay)\
**Post date:** [March 20, 2024, 5:15am UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/7 "2024-03-20T05:15:04Z")

</div>

> [@Sandy1857](#):
>
> unsqeezing

This is how I have run the code

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/3X/3/4/34f78bcc84edf5c2ffed95390f08589fd2b8a72b.png)

---

<div class="post-metadata">

**Author:** ![Sushmitaupadhyay](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sushmitaupadhyay](https://discuss.huggingface.co/u/Sushmitaupadhyay)\
**Post date:** [March 20, 2024, 5:17am UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/8 "2024-03-20T05:17:14Z")

</div>

This output you get after un normalizing. My question is after passing through the ViTImageProcessor why the image gets small and gets arranged in patches. You can refer the output which I have pasted.

---

<div class="post-metadata">

**Author:** ![raygx](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/raygx/32/17328_2.png) [@raygx](https://discuss.huggingface.co/u/raygx)\
**Post date:** [April 18, 2024, 10:15pm UTC](https://discuss.huggingface.co/t/vitimageprocessor-output-visualization/76335/10 "2024-04-18T22:15:19Z")

</div>

I also came across this very question. And finally I figured out what was happening.  
[What is ViTImageProcessor doing? - #4 by raygx](https://discuss.huggingface.co/t/what-is-vitimageprocessor-doing/82132/4).  
Check the last reply that I gave. You’ll know how to reconstruct the image.  
[@everyone](https://discuss.huggingface.co/groups/everyone)
