#学习看官方文档
import torchvision
from torch.utils.tensorboard import SummaryWriter
# train_set = torchvision.datasets.CIFAR10(root='./dataset',train=True,download=True)
# test_set = torchvision.datasets.CIFAR10(root='./dataset',train=False,download=True)
#
# print(test_set[0])
# print(test_set.classes)
# img, target = test_set[0]
# print(img)
# print(target)
# img.show()
# print(test_set.classes[target])
dataset_transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor()])
train_set = torchvision.datasets.CIFAR10(root='./dataset',train=True,transform=dataset_transform,download=True)
test_set = torchvision.datasets.CIFAR10(root='./dataset',train=False,transform=dataset_transform,download=True)
print(test_set[0])
writer = SummaryWriter('logs')
for i in range(10):
img,target = test_set[i]
writer.add_image('test_set',img,i)
writer.close()
torchvision中数据集的使用
最新推荐文章于 2024-11-07 00:52:38 发布
本文介绍了如何使用PyTorch中的torchvision库加载CIFAR10数据集,并演示了如何对测试集进行图像预处理以及使用TensorBoard进行可视化。作者展示了如何在循环中读取测试集样本并将其添加到TensorBoard日志中。
摘要由CSDN通过智能技术生成