@ptrblck, I am having a similar problem but this time using the transforms.Compose class.
What I’ve been trying to do is to create a composition of transformations to apply directly on the torchvision.dataset.Cityscapes dataset object (here I’m using target_type='semantic' ). For simplicity’s sake, let’s say I want to transform the image as a Numpy object with a custom transform, my code for said transform goes like:
class transform_ToNumpy(object):
    # Converts PIL image to Numpy array.
    def __call__(self, image,semseg):
        if not isinstance(image, PIL.Image) or not isinstance(semseg, PIL.Image):
            raise (RuntimeError("segtransform.ToNumpy() only handle PIL.Image"
                                "[eg: data readed by cv2.imread()].\n"))
        else:
          image = np.array(image)
          semseg = np.array(semseg)
            
        return image, semseg

And I am using my transforms.Compose object in the dataset class as:
dataset = Cityscapes(dataset_path, split='train', mode='fine', target_type='semantic', transforms=transforms.Compose([transform_ToNumpy()]))

Notice that I am using the parameter transforms to specify the transform that will be applied to both source and target images.
But I am still getting the error:
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-5-feacc9e6f37e> in <module>()
     26         ]))
     27 
---> 28 img, target = dataset[0] 

/usr/local/lib/python3.6/dist-packages/torchvision/datasets/cityscapes.py in __getitem__(self, index)
    182         if self.transforms is not None:
--> 183             image, target = self.transforms(image, target)
    184 
    185         return image, target

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

Which I don’t understand since my transform’s __call__ method expects two inputs: image and semseg .
Could you give me some insight on why is it saying that:
__call__() takes 2 positional arguments but 3 were given

When I do not specify any other inputs than the source and semantic segmentation images?
Thank you.