PHP前端开发

PyTorch 中的花朵

百变鹏仔 5天前 #Python
文章标签 花朵

请我喝杯咖啡☕

*我的帖子解释了牛津 102 花。

flowers102()可以使用oxford 102 flower数据集,如下所示:

*备忘录:

  • 关于训练和验证图像索引的类别(类)的标签,0是0~9,1是10~19,2是20~29,3是30~39,4是40~49, 5为50~59,6为60~69,7为70~79,8为80~89,9为90~99等
  • 关于测试图像索引的类别(类)标签,0为0~19,1为20~59,2为60~79,3为80~115,4为116~160,5为161~185,6为186~205,7为206~270,8为271~296,9为297~321等。
  • from torchvision.datasets import Flowers102train_data = Flowers102(    root="data")train_data = Flowers102(    root="data",    split="train",    transform=None,    target_transform=None,    download=False)val_data = Flowers102(    root="data",    split="val")test_data = Flowers102(    root="data",    split="test")len(train_data), len(val_data), len(test_data)# (1020, 1020, 6149)train_data# Dataset Flowers102#     Number of datapoints: 1020#     Root location: data#     split=traintrain_data.root# 'data'train_data._split# 'train'print(train_data.transform)# Noneprint(train_data.target_transform)# Nonetrain_data.download# <bound method Flowers102.download of Dataset Flowers102#     Number of datapoints: 1020#     Root location: data#     split=train>len(set(train_data._labels)), train_data._labels# (102,#  [0, 0, 0, ..., 1, ..., 2, ..., 3, ..., 4, ..., 5, ..., 6, ..., 101])train_data[0]# (<PIL.Image.Image image mode=RGB size=754x500>, 0)train_data[1]# (<PIL.Image.Image image mode=RGB size=624x500>, 0)train_data[2]# (<PIL.Image.Image image mode=RGB size=667x500>, 0)train_data[10]# (<PIL.Image.Image image mode=RGB size=500x682>, 1)train_data[20]# (<PIL.Image.Image image mode=RGB size=667x500>, 2)val_data[0]# (<PIL.Image.Image image mode=RGB size=606x500>, 0)val_data[1]# (<PIL.Image.Image image mode=RGB size=667x500>, 0)val_data[2]# (<PIL.Image.Image image mode=RGB size=500x628>, 0)val_data[10]# (<PIL.Image.Image image mode=RGB size=500x766>, 1)val_data[20]# (<PIL.Image.Image image mode=RGB size=624x500>, 2)test_data[0]# (<PIL.Image.Image image mode=RGB size=523x500>, 0)test_data[1]# (<PIL.Image.Image image mode=RGB size=666x500>, 0)test_data[2]# (<PIL.Image.Image image mode=RGB size=595x500>, 0)test_data[20]# (<PIL.Image.Image image mode=RGB size=500x578>, 1)test_data[60]# (<PIL.Image.Image image mode=RGB size=500x625>, 2)import matplotlib.pyplot as pltdef show_images(data, ims, main_title=None):    plt.figure(figsize=(10, 5))    plt.suptitle(t=main_title, y=1.0, fontsize=14)    for i, j in enumerate(ims, start=1):        plt.subplot(2, 5, i)        im, lab = data[j]        plt.imshow(X=im)        plt.title(label=lab)    plt.tight_layout()    plt.show()train_ims = (0, 1, 2, 10, 20, 30, 40, 50, 60, 70)val_ims = (0, 1, 2, 10, 20, 30, 40, 50, 60, 70)test_ims = (0, 1, 2, 20, 60, 80, 116, 161, 186, 206)show_images(data=train_data, ims=train_ims, main_title="train_data")show_images(data=train_data, ims=val_ims, main_title="val_data")show_images(data=test_data, ims=test_ims, main_title="test_data")