Training with a random fraction data from data loader every epoch


I have a very large dataset to train my model. I would like to get n different random batches from the DataLoader at every different epoch. How can I do it?


You could create an iterator via loader_iter = iter(loader) and get the next batch via batch = next(iter). If you’ve set shuffle=True in the DataLoader, these batches will contain random samples.