I’m trying to train a deep neural network sampling my images with replacement. In other words, if I have for example a batch size of 10, and a data-set made of (let’s say) 1000 images, I would like to create 100 batches where each sample is randomly sampled from the whole data-set.
What I’m doing is the following:
random_train_loader = torch.utils.data.DataLoader(
torchvision.datasets.MNIST('./datasets/', train=True, transform=torchvision.transforms.ToTensor()),
for input_images, labels in iter(random_train_loader):
# I do stuff
Sadly this build a
object of type 'type' has no len()
I’ve probably misunderstood the documentation of RandomSampler, any suggestion?
Yes, a dataset instance should be an instance of a class derived from torch.utils.data.Dataset. So, torchvision.datasets.MNIST and torch.utils.data.TensorDataset are both derived from torch.utils.data.Dataset.