PyTorch 中的斯坦福汽车
请我喝杯咖啡☕
*我的帖子解释了斯坦福汽车。
stanfordcars()可以使用stanford cars数据集,如下所示:
*备忘录:
data └-stanford_cars |-cars_test_annos_withlabels.mat |-cars_test | └-*.jpg |-cars_train | └-*.jpg └-devkit |-cars_meta.mat |-cars_test_annos.mat |-cars_train_annos.mat |-eval_train.m |-readme.txt └-train_perfect_preds.txt
from torchvision.datasets import StanfordCarstrain_data = StanfordCars( root="data")train_data = StanfordCars( root="data", split="train", transform=None, target_transform=None, download=False)test_data = StanfordCars( root="data", split="test")len(train_data), len(test_data)# (8144, 8041)train_data# Dataset StanfordCars# Number of datapoints: 8144# Root location: datatrain_data.root# 'data'train_data._split# 'train'print(train_data.transform)# Noneprint(train_data.target_transform)# Nonetrain_data.download# <bound method StanfordCars.download of Dataset StanfordCars# Number of datapoints: 8144# Root location: data>len(train_data.classes), train_data.classes# (196,# ['AM General Hummer SUV 2000', 'Acura RL Sedan 2012', 'Acura TL Sedan 2012',# 'Acura TL Type-S 2008', ..., 'Volvo 240 Sedan 1993',# 'Volvo XC90 SUV 2007', 'smart fortwo Convertible 2012'])train_data[0]# (<PIL.Image.Image image mode=RGB size=600x400>, 13)train_data[1]# (<PIL.Image.Image image mode=RGB size=900x675>, 2)train_data[2]# (<PIL.Image.Image image mode=RGB size=640x480>, 90)train_data[3]# (<PIL.Image.Image image mode=RGB size=2100x1386>, 133)train_data[4]# (<PIL.Image.Image image mode=RGB size=144x108>, 105)import matplotlib.pyplot as pltdef show_images(data, main_title=None): plt.figure(figsize=(12, 5)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, (im, lab) in zip(range(1, 11), data): plt.subplot(2, 5, i) plt.imshow(X=im) plt.title(label=lab) plt.tight_layout() plt.show()show_images(data=train_data, main_title="train_data")show_images(data=test_data, main_title="test_data")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")