I have created a concatenated dataset using `torch.utils.data.ConcatDataset, now I would like to load the data using data loader and use the sample feature. The sampler I am using is the following:
What kind of Dataset
are you passing to ConcatDataset
?
Currently the implementation you’ve linked seems to only work with the MNIST dataset and ImageFolder
, see this line of code.
You could try to implement the _get_label
method for your dataset or alternatively you could try to use the built-in WeightedRandomSampler
.
Here is the code I am using :
trainset=ConcatDataset([(datasets.ImageFolder(train_dir, train_transform)),datasets.ImageFolder(train_dir, valid_transform)])
trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,shuffle=True)
what I would like to do is:
trainset=ConcatDataset([(datasets.ImageFolder(train_dir, train_transform)),datasets.ImageFolder(train_dir, valid_transform)])
trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,sampler=any_sampler_function(trainset),shuffle=False)
I think I tried WeightedRandomSampler but the error I get is the same as using the custom sampler, something like “a tuple was provided while a sampler object is required”.