# Image dataset with\_transform not applied

**URL:** <https://discuss.huggingface.co/t/image-dataset-with-transform-not-applied/98836>\
**Category:** Beginners\
**Created:** [July 22, 2024, 11:44pm UTC](https://discuss.huggingface.co/t/image-dataset-with-transform-not-applied/98836 "2024-07-22T23:44:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimitrije-it](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@dimitrije-it](https://discuss.huggingface.co/u/dimitrije-it)\
**Post date:** [July 22, 2024, 11:44pm UTC](https://discuss.huggingface.co/t/image-dataset-with-transform-not-applied/98836/1 "2024-07-22T23:44:54Z")

</div>

Hi,

I am training a computer vision model and want to apply AutoImageProcessor to prepare images for model.

When I use with\_transform and the use a trainer, transformation is not applied.

Dataset contains PIL images.

```auto
from transformers import AutoImageProcessor
image_processor = AutoImageProcessor.from_pretrained('google/vit-base-patch16-224-in21k', use_fast=True)

def transform(example):
    ds = {}
    ds['image'] = image_processor(example, return_tensors='pt')['pixel_values'].reshape(3,224,224)
    return ds

dataset = dataset.with_transform(transform)

```

When I use .map it works, but I have a large dataset and map is taking too much space.

Any ideas why with\_transform is not called at all? I also have tried with DataLoader and transformation is not applied.

---

<div class="post-metadata">

**Author:** ![qubvel-hf](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/qubvel-hf/32/32371_2.png) [@qubvel-hf](https://discuss.huggingface.co/u/qubvel-hf)\
**Post date:** [July 25, 2024, 4:40pm UTC](https://discuss.huggingface.co/t/image-dataset-with-transform-not-applied/98836/2 "2024-07-25T16:40:51Z")

</div>

Hi @dimitrije-it , `with_transform` works fine for the following snippet:

```python
import datasets
print("Datasets version:", datasets. __version__ )

from transformers import AutoImageProcessor
from datasets import load_dataset

image_processor = AutoImageProcessor.from_pretrained('google/vit-base-patch16-224-in21k', use_fast=True)
dataset = load_dataset("zh-plus/tiny-imagenet")["train"]

def transform(example):
    inputs = image_processor(example["image"], return_tensors='pt')['pixel_values'].reshape(3,224,224)
    return {
        "image": inputs,
        "label": example["label"]
    }

dataset = dataset.with_transform(transform)
print(dataset[0])

```

```auto
Datasets version: 2.20.0
{'image': tensor([[1.0000, 1.0000, 1.0000, ..., 0.1373, -0.0039, -0.0039],
        [1.0000, 1.0000, 1.0000, ..., 0.1373, -0.0039, -0.0039],
        [1.0000, 1.0000, 1.0000, ..., 0.1294, -0.0118, -0.0118],
        ...,
        [-0.2863, -0.2863, -0.2863, ..., -0.4039, -0.4118, -0.4118],
        [-0.2863, -0.2863, -0.2863, ..., -0.4275, -0.4353, -0.4353],
        [-0.2863, -0.2863, -0.2863, ..., -0.4275, -0.4353, -0.4353]]), 'label': 0}

```
