Hello everyone!
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()),
batch_size=batch_size,
sampler=torch.utils.data.sampler.RandomSampler(torchvision.datasets.MNIST, replacement=True)
)
for input_images, labels in iter(random_train_loader):
# I do stuff
Sadly this build a
object of type 'type' has no len()
error.
I’ve probably misunderstood the documentation of RandomSampler, any suggestion?
dataset “the same thing” as the dataset you define in your example? Where with “the same thing” I mean “another instance of the same class” (I suppose). So I can treat them equivalently?
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.