# Pass transformation to Cityscapes dataset

**URL:** <https://discuss.pytorch.org/t/pass-transformation-to-cityscapes-dataset/136124>\
**Category:** Uncategorized\
**Created:** [November 5, 2021, 8:25pm UTC](https://discuss.pytorch.org/t/pass-transformation-to-cityscapes-dataset/136124 "2021-11-05T20:25:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![talhaanwarch](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/talhaanwarch/32/26568_2.png) [@talhaanwarch](https://discuss.pytorch.org/u/talhaanwarch)\
**Post date:** [November 5, 2021, 8:25pm UTC](https://discuss.pytorch.org/t/pass-transformation-to-cityscapes-dataset/136124/1 "2021-11-05T20:25:54Z")

</div>

Hi, greetings, i want to transform both image and mask. I tried this way

```auto
from torchvision.datasets import Cityscapes
from torchvision import transforms as T
aug=T.Compose([T.Resize((256,512))])
dataset = Cityscapes('../data/', split='val', mode='fine',
                     target_type='semantic',transforms=aug)

```

but it gives me following error

```auto
TypeError Traceback (most recent call last)
/tmp/ipykernel_348578/797377544.py in <module>
      7 target_type='semantic',transforms=aug)
      8 
----> 9 out= dataset[2]
     10 print(out[0].size,out[1].size)
     11 #img,seg=augment(np.array(out[0]),np.array(out[1]))

~/venv/lib/python3.8/site-packages/torchvision/datasets/cityscapes.py in __getitem__ (self, index)
    190 
    191 if self.transforms is not None:
--> 192 image, target = self.transforms(image, target)
    193 
    194 return image, target

TypeError: __call__ () takes 2 positional arguments but 3 were given

```

---

<div class="post-metadata">

**Author:** ![L-Reichardt](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/l/59ef9b/32.png) [@L-Reichardt](https://discuss.pytorch.org/u/L-Reichardt)\
**Post date:** [January 28, 2022, 2:01pm UTC](https://discuss.pytorch.org/t/pass-transformation-to-cityscapes-dataset/136124/2 "2022-01-28T14:01:48Z")

</div>

A little late, but maybe someone will read it. You could try removing the keyword `transforms=aug`. Instead try `Cityscapes(...., transform=aug, target_transform=aug)`. Note that there are `transform` and `transforms` as two different keywords.

If that doesnt work, you could try removing `aug=T.Compose(...)`, and instead create a class.

```auto
class CityTransform:
    def __call__ (self, image, target):
        image = *your transformation* (image)
        target = *your transformation* (target)
        return image, target

```

then insert it

```auto
dataset = Cityscapes('../data/', split='val', mode='fine',
                     target_type='semantic',transforms=CityTransform)

```
