DataLoader
- 使用dataloader方便数据取出。定义CustomDataset类方便对接dataloader类型
class CustomDataset(torch.utils.data.Dataset):
def __init__(self):
# TODO
# 1. Initialize file paths or a list of file names.
pass
def __getitem__(self, index):
# TODO
# 1. Read one data from file (e.g. using numpy.fromfile, PIL.Image.open).
# 2. Preprocess the data (e.g. torchvision.Transform).
# 3. Return a data pair (e.g. image and label).
pass
def __len__(self):
# You should change 0 to the total size of your dataset.
return 0
custom_dataset = CustomDataset()
train_loader=torch.utils.data.DataLoader(dataset=custom_dataset,batch_size=64,shuffle=True)
data_iter=iter(train_loader)#迭代器方便取minibatch
images,labels=data_iter.next()#取出一个mini-batch的数据
举例: