VOC datasets's __getitem__() method not working?

import torchvision.transforms as transforms

data=torchvision.datasets.VOCSegmentation("./",download=True,transforms=transforms.Compose([transforms.ToTensor()]))

img,tar=data[0]

I get following error:

/usr/local/lib/python3.6/dist-packages/torchvision/datasets/voc.py in getitem(self, index)
205
206 if self.transforms is not None:
–> 207 img, target = self.transforms(img, target)
208
209 return img, target

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

You are currently trying to pass a single transformation to transforms, which expects a StandardTransform object as seen here.
Try to use transform=transforms.ToTensor() instead (note the missing s on the left hand side) to transform the data.
If you also want to pass a transformation for the target image, use target_transform additionally.

1 Like

Thanks for the help. :smiley: