8 加载数据集DataLoader官方(len(dataset)/batch_size)
涉及两个类:dataset&DataLoader
dataset
DataLoader
https://www.bilibili.com/video/BV1hE411t7RN?p=15
import torchvision.datasets
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10("../data", train=True, transform=torchvision.transforms.ToTensor(),
download=True)
#
dataloader = DataLoader(dataset, batch_size=64, shuffle=True, num_workers=0, drop_last=True) # drop_last=True 表示最后一个bath舍弃
writer = SummaryWriter("../logs/dataloader")
for epoch in range(2):
step=0
for data in dataloader:
imgs, target = data
print(imgs.shape)
print(target)
writer.add_images("Epoch_%d"%(epoch), imgs, step)
step +=1
writer.close()