I am new to PyTorch and I am learning to create batches of data for segmentation. The code is shown below:
class NumbersDataset(Dataset):
def __init__(self):
self.X = list(df['input_img'])
self.y = list(df['mask_img'])
def __len__(self):
return len(self.X), len(self.y)
def __getitem__(self, idx):
return self.X[idx], self.y[idx]
if __name__ == '__main__':
dataset = NumbersDataset()
dataloader = DataLoader(dataset, batch_size=50, shuffle=True, num_workers=2)
# print(len(dataset))
# plt.imshow(dataset[100])
# plt.show()
print(next(iter(dataloader)))
where df['input_img'] column contains the location of the image ('/path/to/pic/480p/boxing-fisheye/00010.jpg') and df['mask_img'] contains the location of all the mask images. I am trying to load the images but I get the error:
TypeError: 'tuple' object cannot be interpreted as an integer
However, if I don't use DataLoader and just do the following:
dataset = NumbersDataset()
print(len(dataset))
print(dataset[10:20])
then I get what I expect. Can someone tell me what am I doing wrong?