import torchvision
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset_transform = torchvision.transforms.Compose([
torchvision.transforms.ToTensor()
])
# 准备数据集
train_set = torchvision.datasets.CIFAR10(root='E:\\pythonProject\\resources\\cifar', transform=dataset_transform,
train=True, download=True)
test_set = torchvision.datasets.CIFAR10(root='E:\\pythonProject\\resources\\cifar', transform=dataset_transform,
train=False, download=True)
# 导入数据集,准备模型
test_loader = DataLoader(dataset=test_set, batch_size=64, shuffle=True, num_workers=0, drop_last=False)
# 初始化模型,参量
writer = SummaryWriter(log_dir="data_loader")
step = 0
# 取出数据集中数据
for epoch in range(2):
for data in test_loader:
imgs, targets = data
writer.add_images(tag="dataloader{}".format(epoch), img_tensor=imgs, global_step=step)
step = step + 1
# 关闭模型
writer.close()
在运行开始后,在终端在输入如下调用tensorboard
点击其中超链接进入网页查看运行结果。
这里代码调试好,先睡觉了T T