I tried to pass a list of indices to the dataset however the __getitem__
function in my custom dataset The list of indices is from BatchSampler
. But I’m getting a Type Error list indices must be integers or slices, not list
when running the code.
How do I solve this issue?
class MyData(Dataset):
def __init__(self, data, transform = None):
self.data = data
self.transform = transform
def __getitem__(self, index):
img, label = self.data[index] #<------ The error occurs here
if self.transform is not None:
img = self.transform(img)
return img, label
def __len__(self):
return len(self.data)
training_set = MyData(trainset,transform = train_aug)
sampler = torch.utils.data.sampler.BatchSampler(
torch.utils.data.sampler.RandomSampler(training_set),
batch_size=10,
drop_last=False)
trainloader = DataLoader(
training_set,
sampler=sampler)