"""
本节学会如何下载数据集,并通过tensorboard查看下载的数据集
"""
import torchvision
import ssl
from torch.utils.tensorboard import SummaryWriter
ssl._create_default_https_context = ssl._create_unverified_context # 全局取消证书验证
# Compose中存放transforms列表,列表中有totensor和resize两种方法
dataset_transfroms = torchvision.transforms.Compose([torchvision.transforms.ToTensor(),torchvision.transforms.Resize((512,512))])
#这个时候也可以按着Ctrl鼠标点击CIFAR10进入,往上滑,找到数据集的下载链接去浏览器中下载即可
train_set = torchvision.datasets.CIFAR10(root='./torchvision_dataset',train=True,download=True,transform=dataset_transfroms)
test_set = torchvision.datasets.CIFAR10(root='./torchvision_dataset',train=False,download=True,transform=dataset_transfroms)
#print(train_set[0])
# img,target = train_set[0]
# print(img)
# print(target)
writer = SummaryWriter('dataset_log')
for i in range(10):
img,target = train_set[i]
writer.add_image('train_set',img,i)
writer.close()
pytorch入门6:学会如何下载数据集,并通过tensorboard查看下载的数据集
最新推荐文章于 2024-07-09 15:17:23 发布