import matplotlib.pyplot as plt
下载数据集,并将数据集变成DataLoader类型
train_set = CIFAR10('./data', train=True, transform=data_tf,download=True)
train_data = torch.utils.data.DataLoader(train_set, batch_size=64, shuffle=True)
test_set = CIFAR10('./data', train=False, transform=data_tf,download=True)
test_data = torch.utils.data.DataLoader(test_set, batch_size=128, shuffle=False)
遍历数据集,这里只查看三张图片
cnt = 0
for image, label in train_data:
if cnt >= 3:
break
print(image.shape)
img = image[0]
img = img.numpy()
img = np.transpose(img, (1, 2, 0))
plt.imshow(img)
plt.show()
cnt += 1
输出的image.shape是torch.Size([64, 3, 32, 32])
batch中有64张图片,彩色三通道,大小为32*32