Will dataset be shuffled for each epoch?

Hi,

I define the dataloader as the following code.
will the dataset be shuffled for each epoch?

    dataloader = torch.utils.data.DataLoader(dataset,
                        batch_size=batch_size,
                        num_workers=nw,
                        sampler=sampler,
                        shuffle=True,
                        pin_memory=False, )

Hi,

You are required to specify either of sampler or shuffle as arguments to the dataloader.
You cannot specify both.

In case, you want the data to be shuffled at every epoch and get sampled according to a randomsampler, specify shuffle=True and remove the sampler argument.

If you specify a sampler, the sampling scheme implied by your custom sampler shall be used.

Hi @srishti-git1110
Thank you!

I should set sampler=None, or just don’t set anything?

    dataloader = torch.utils.data.DataLoader(dataset,
                        batch_size=batch_size,
                        num_workers=nw,
                        sampler=None,
                        shuffle=True,
                        pin_memory=False, )

Do not specify it. It’ll work fine then.

dataloader = torch.utils.data.DataLoader(dataset,
                        batch_size=batch_size,
                        num_workers=nw,
                        shuffle=True,
                        pin_memory=False)

@srishti-git1110
Got it. Thank you!