What is the use of the shuffle=True of dataloader in PyTorch
This article mainly shows you "what is the use of dataloader shuffle=True in PyTorch", the content is simple and clear, hoping to help you solve your doubts, let the editor lead you to study and learn "what is the use of dataloader shuffle=True in PyTorch" this article.
Understanding of shuffle=True:
I didn't know the actual effect of shuffle before. Suppose I have some data, such as a batch_size=2, I don't know how to disturb it, which of the following is the specific case?
1. First take the batch in order, and then disrupt the batch, that is, first take a dagger, b, and then disrupt the internal batch.
two。 First disturb, then take the batch.
Proved to be the second shuffle (bool, optional): set to ``True`` to have the data reshuffled at every epoch (default: ``False``). If shuffle: sampler = RandomSampler (dataset) # what you get at this time is the index
Add: simply test how shuffle=True works in pytorch dataloader
Look at the code ~ import sysimport torchimport randomimport argparseimport numpy as npimport pandas as pdimport torch.nn as nnfrom torch.nn import functional as Ffrom torch.optim import lr_schedulerfrom torchvision import datasets, transformsfrom torch.utils.data import TensorDataset, DataLoader, Dataset class DealDataset (Dataset): def _ _ init__ (self): xy = np.loadtxt (open ('. / iris.csv','rb'), delimiter=',', dtype=np.float32) # data = pd.read_csv ("iris.csv" Header=None) # xy = data.values self.x_data = torch.from_numpy (xy [:, 0xy [:]) self.y_data = torch.from_numpy (xy [:, [- 1]]) self.len = xy.shape [0] def _ _ getitem__ (self, index): return self.x_ data [index] Self.y_ data [index] def _ len__ (self): return self.len dealDataset = DealDataset () train_loader2 = DataLoader (dataset=dealDataset, batch_size=2, shuffle=True) # print (dealDataset.x_data) for I, data in enumerate (train_loader2): inputs, labels = data # inputs, labels = Variable (inputs) Variable (labels) print (inputs) # print ("epoch:", epoch, "No.", I, "inputs", inputs.data.size (), "labels", labels.data.size ()) are all the contents of the article "what is the shuffle=True of dataloader in PyTorch?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!