How to get entire dataset from dataloader in PyTorch

Aakanksha W.S picture Aakanksha W.S · Aug 7, 2019 · Viewed 13.5k times · Source

How to load entire dataset from the DataLoader? I am getting only one batch of dataset.

This is my code

dataloader = torch.utils.data.DataLoader(dataset=dataset, batch_size=64)
images, labels = next(iter(dataloader))

Answer

asymptote picture asymptote · Aug 7, 2019

You can set batch_size=dataset.__len__() in case dataset is torch Dataset, else something like batch_szie=len(dataset) should work.

Beware, this might require a lot of memory depending upon your dataset.