Im following the example here, regarding torchvision.datasets.
In the example we have:
imagenet_data = torchvision.datasets.ImageFolder('path/to/imagenet_root/')
data_loader = torch.utils.data.DataLoader(imagenet_data,
batch_size=,
shuffle=True,
num_workers=args.nThreads)
I am wondering if there is a way that I can know the number of images in data_loader? I want to check its size and see how many images is in it…
Thank you
3 Likes
smth
#2
you can do:
print(len(imagenet_data))
8 Likes
Peter_Cha
(Peter Cha)
#3
You can get the length of dataloder’s dataset like this:
print(len(dataloader.dataset))
29 Likes
How would we do the same when we use sampler=torch.utils.data.SubsetRandomSampler()
when creating the dataloader?
indices = np.arange(0, len(dataset))
train_dl = DataLoader(dataset, bs, sampler=torch.utils.data.SubsetRandomSampler(indices[:300]))
test_dl = DataLoader(dataset, bs, sampler=torch.utils.data.SubsetRandomSampler(indices[-300:]))
len(train_dl.dataset) == len(test_dl.dataset)
len(loader.dataset.indices)
should give you the number of images in the dataloader
1 Like