DataLoader
Role: 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, DataLoader
is 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:
- Create an
dataset
Object - Create an
DataLoader
Object - Traversing the
DataLoader
object willdata
,label
loaded 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:
...
DataLoader
There 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