import torchvision
import ssl
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
ssl._create_default_https_context = ssl._create_unverified_context #取消全局证书验证
dataset_transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor()])
test_data = torchvision.datasets.CIFAR10(root="./dataset",train=False,transform=dataset_transform,download = True)
test_loader = DataLoader(dataset=test_data,batch_size=64,shuffle=True,num_workers=0,drop_last=False)
# batch_size=4 取四个数据打包,默认随机抓取
# drop_last=False 当为True时,舍弃后面不足的数据
# shuffle=True 当第二轮洗牌时,顺序是否和第一轮相同
# 测试数据集第一张数据集
writer = SummaryWriter("dataloader1")
for epoch in range(2):
step = 0
for data in test_loader:
imgs,targets = data
writer.add_images("epoch: {}".format(epoch), imgs, step) #多组图像要用add_images
step = step+1
writer.close()
torchvision.datasets.CIFAR10的使用
最新推荐文章于 2024-08-25 10:47:03 发布