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
4 Likes
smth
2
you can do:
print(len(imagenet_data))
9 Likes
You can get the length of dataloder’s dataset like this:
print(len(dataloader.dataset))
36 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)
2 Likes
len(loader.dataset.indices)
should give you the number of images in the dataloader
1 Like
You can do with:
len(train_loader.sampler.indices)
1 Like
scchess
(Ted Wong)
8
print(len(dataloader.dataset)) worked