I have a certain dataset loaded into a dataloader. For example, if I wanted to save 100 images from this dataloader, how should I iterate over the dataloader to save them?
Asked
Active
Viewed 5,047 times
1
-
Hi @CaxiomX20, welcome to SO! What have you tried so far? Please help us by providing a little more information – M Z Aug 03 '20 at 17:01
2 Answers
0
Im not exactly sure what you are trying to do (maybe edit your question) but maybe this helps:
dataset = Dataset()
dataloader = torch.utils.data.DataLoader(
dataloader,
batch_size=32,
num_workers=1,
shuffle=True)
for samples, targets in dataloader:
# 'sample' now is a batch of 32 (see batch-size above) elements of your dataset
Is this what you wanted? Hope so :)

Theodor Peifer
- 3,097
- 4
- 17
- 30
0
Take dl
as your dataloader.
If you want to print only the first batch you can do this:
for data, targets in dl:
print #whatever you want
break
But if you want the n-th batch you can do this:
for batch_idx, (data, target) in enumerate(train_loader):
if batch_idx == n:
print #whatever you want
break

Peyman
- 3,097
- 5
- 33
- 56