My goal is to train a pre-trained object segmentation model using my own dataset with its own classes. So, I created my own dataset using the COCO Dataset format.
Here below, you can see that I am trying to create a Dataset using the function CocoDetection.
import torchvision.datasets as dset

def get_transform():
    custom_transforms = []
    custom_transforms.append(T.ToTensor())
    return T.Compose(custom_transforms)

coco_test = dset.CocoDetection(root = root_dir,
                                annFile = test_json,
                                transforms=get_transform())

# Test if dataset is working
for i in range(len(coco_train)):
  sample = coco_train[i]
  print(sample[0])

  if i == 3:
    break

At first, I tried without applying any transformations at all and it worked. However, after I added a transform on the function, it did not work. I checked the error and it says that the call takes 2 positional argument, but 3 were given. But, I inspected the source code, and I am giving it 2 arguments. I don’t know what’s the problem. I don’t know what to do next. Please help. Here’s the full error. By the way, I am using Google Colab.
---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

<ipython-input-13-bc0dddb4b6c5> in <module>()
      1 for i in range(len(coco_train)):
----> 2   sample = coco_train[i]
      3   print(sample[0])
      4 
      5   if i == 3:

/usr/local/lib/python3.6/dist-packages/torchvision/datasets/coco.py in __getitem__(self, index)
    116         img = Image.open(os.path.join(self.root, path)).convert('RGB')
    117         if self.transforms is not None:
--> 118             img, target = self.transforms(img, target)
    119 
    120         return img, target

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