PyTorch DataLoader () use

DataLoaderRole: Usually we will in the training data set into a number of small, random batch , of course, this operation can be operated manually, but PyTorch which gives us the API allows us easy access to batch from the dataset, DataLoaderis more do children's.
Look at the description of official documents, including the definition of each parameter:

it's essentially a iterable, normal operation is:

  1. Create an datasetObject
  2. Create an DataLoaderObject
  3. Traversing the DataLoaderobject will data, labelloaded into the model train
#一个粗略的示意
dataset = torchvision.datasets.MNIST()  #从torchvision这个包里获得一个dataset对象
train_iter = torch.utils.data.DataLoader(dataset, batch_size = args.batch_size, shuffle = True)#创建DataLoader对象
for epoch in num(epochs):#将数据加载到模型之中
    for data, label in train_iter:
        ...

DataLoaderThere are many more details, but have not yet met, so the first note of this part.
This speaks good blog on this topic, refer https://www.cnblogs.com/ranjiewen/p/10128046.html

Guess you like

Origin www.cnblogs.com/patrolli/p/11870141.html