Overwriting PyTorch DataLoader shuffle?

Is it possible to write a custom dataloader / are there any examples? I’d like to customize the shuffle function.

you can use custom sampler in torch.utils.data.DataLoader

  • sampler (Sampler or Iterable , optional) – defines the strategy to draw samples from the dataset. Can be any Iterable with __len__ implemented. If specified, shuffle must not be specified.

Thanks! Would you recommend overwriting both the sampler and batch_sampler? Or is one sufficient? I plan to use a batch size higher than 1.

i think setting up sampler is enough.

1 Like

In DataLoader, sampler and batch_sampler are mutually exclusive.
The option is to either use sampler with batch_size > 1 or to use batch_sampler.