PyTorch 中的 CIFAR
请我喝杯咖啡☕
*我的帖子解释了 cifar-10。
cifar10()可以使用cifar-10数据集,如下所示:
*备忘录:
from torchvision.datasets import CIFAR10train_data = CIFAR10( root="data")train_data = CIFAR10( root="data", train=True, transform=None, target_transform=None, download=False)test_data = CIFAR10( root="data", train=False)len(train_data), len(test_data)# (50000, 10000)train_data# Dataset CIFAR10# Number of datapoints: 50000# Root location: data# Split: Traintrain_data.root# 'data'train_data.train# Trueprint(train_data.transform)# Noneprint(train_data.target_transform)# Nonetrain_data.download# bound method CIFAR10.download of Dataset CIFAR10# Number of datapoints: 50000# Root location: data# Split: Train>len(train_data.classes)# 10train_data.classes# ['airplane', 'automobile', 'bird', 'cat', 'deer',# 'dog', 'frog', 'horse', 'ship', 'truck']train_data[0]# (<PIL.Image.Image image mode=RGB size=32x32>, 6)train_data[1]# (<PIL.Image.Image image mode=RGB size=32x32>, 9)train_data[2]# (<PIL.Image.Image image mode=RGB size=32x32>, 9)train_data[3]# (<PIL.Image.Image image mode=RGB size=32x32>, 4)train_data[4]# (<PIL.Image.Image image mode=RGB size=32x32>, 1)import matplotlib.pyplot as pltdef show_images(data, main_title=None): plt.figure(figsize=(10, 5)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, (im, lab) in enumerate(data, start=1): plt.subplot(2, 5, i) plt.title(label=lab) plt.imshow(X=im) if i == 10: break plt.tight_layout() plt.show()show_images(data=train_data, main_title="train_data")show_images(data=test_data, main_title="test_data")