Say I am loading MNIST from torchvision.datasets.MNIST
, but I only want to load in 10000 images total, how would I slice the data to limit it to only some number of data points? I understand that the DataLoader
is a generator yielding data in the size of the specified batch size, but how do you slice datasets?
tr = datasets.MNIST('../data', train=True, download=True, transform=transform)
te = datasets.MNIST('../data', train=False, transform=transform)
train_loader = DataLoader(tr, batch_size=args.batch_size, shuffle=True, num_workers=4, **kwargs)
test_loader = DataLoader(te, batch_size=args.batch_size, shuffle=True, num_workers=4, **kwargs)
train_loader
multiple times in a loop over variableepoch
, you may have already used all the samples for the training... Because theshuffle=True
option inDataLoader
will shuffle the samples for each epoch. – Painless