Bixqu
August 7, 2017, 9:54am
1
I am training a very simple net on CIFAR10 and I want to get the number of examples from the loader,
trainset = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=4, shuffle=True, num_workers=2)
Is there a way to use trainloader.number_of_examples or something similar?
fmassa
(Francisco Massa)
August 7, 2017, 10:25am
2
The number of examples is present from the dataset, not the dataloader.
So you can get the number of examples by using len(trainset)
how about telling dataloader how many samples to load? Is that possible?
You could use a SubsetSampler, pass the desired indices to it, and pass the sampler to the DataLoader in order to define the number of returned samples.
Juans
February 1, 2022, 11:12am
6
If anyone is looking to get the number of data points in the training set from the DataLoader object:
len(trainloader.dataset)
In contrast len(trainloader) which gives the “number of batches”, see however second warning in the docs .