Beli Saya Kopi☕
*Siaran saya menerangkan Oxford-IIIT Pet.
OxfordIIITPet() boleh menggunakan dataset Oxford-IIIT Pet seperti ditunjukkan di bawah:
*Memo:
from torchvision.datasets import OxfordIIITPet trainval_cate_data = OxfordIIITPet( root="data" ) trainval_cate_data = OxfordIIITPet( root="data", split="trainval", target_types="category", transform=None, target_transform=None, download=False ) trainval_bincate_data = OxfordIIITPet( root="data", split="trainval", target_types="binary-category" ) test_seg_data = OxfordIIITPet( root="data", split="test", target_types="segmentation" ) test_empty_data = OxfordIIITPet( root="data", split="test", target_types=[] ) test_all_data = OxfordIIITPet( root="data", split="test", target_types=["category", "binary-category", "segmentation"] ) len(trainval_cate_data), len(trainval_bincate_data) # (3680, 3680) len(test_seg_data), len(test_empty_data), len(test_all_data) # (3669, 3669, 3669) trainval_cate_data # Dataset OxfordIIITPet # Number of datapoints: 3680 # Root location: data trainval_cate_data.root # 'data' trainval_cate_data._split # 'trainval' trainval_cate_data._target_types # ['category'] print(trainval_cate_data.transform) # None print(trainval_cate_data.target_transform) # None trainval_cate_data._download # <bound method OxfordIIITPet._download of Dataset OxfordIIITPet # Number of datapoints: 3680 # Root location: data> len(trainval_cate_data.classes), trainval_cate_data.classes # (37, # ['Abyssinian', 'American Bulldog', 'American Pit Bull Terrier', # 'Basset Hound', 'Beagle', 'Bengal', 'Birman', 'Bombay', 'Boxer', # 'British Shorthair', ..., 'Wheaten Terrier', 'Yorkshire Terrier']) trainval_cate_data[0] # (<PIL.Image.Image image mode=RGB size=394x500>, 0) trainval_cate_data[1] # (<PIL.Image.Image image mode=RGB size=450x313>, 0) trainval_cate_data[2] # (<PIL.Image.Image image mode=RGB size=500x465>, 0) trainval_bincate_data[0] # (<PIL.Image.Image image mode=RGB size=394x500>, 0) trainval_bincate_data[1] # (<PIL.Image.Image image mode=RGB size=450x313>, 0) trainval_bincate_data[2] # (<PIL.Image.Image image mode=RGB size=500x465>, 0) test_seg_data[0] # (<PIL.Image.Image image mode=RGB size=300x225>, # <PIL.PngImagePlugin.PngImageFile image mode=L size=300x225>) test_seg_data[1] # (<PIL.Image.Image image mode=RGB size=300x225>, # <PIL.PngImagePlugin.PngImageFile image mode=L size=300x225>) test_seg_data[2] # (<PIL.Image.Image image mode=RGB size=229x300>, # <PIL.PngImagePlugin.PngImageFile image mode=L size=229x300>) test_empty_data[0] # (<PIL.Image.Image image mode=RGB size=300x225>, None) test_empty_data[1] # (<PIL.Image.Image image mode=RGB size=300x225>, None) test_empty_data[2] # (<PIL.Image.Image image mode=RGB size=229x300>, None) test_all_data[0] # (<PIL.Image.Image image mode=RGB size=300x225>, # (0, 0, <PIL.PngImagePlugin.PngImageFile image mode=L size=300x225>)) test_all_data[1] # (<PIL.Image.Image image mode=RGB size=300x225>, # (0, 0, <PIL.PngImagePlugin.PngImageFile image mode=L size=300x225>)) test_all_data[2] # (<PIL.Image.Image image mode=RGB size=229x300>, # (0, 0, <PIL.PngImagePlugin.PngImageFile image mode=L size=229x300>)) import matplotlib.pyplot as plt def show_images(data, ims, main_title=None): if len(data._target_types) == 0: plt.figure(figsize=(12, 6)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, j in enumerate(ims, start=1): plt.subplot(2, 5, i) im, _ = data[j] plt.imshow(X=im) elif len(data._target_types) == 1: if data._target_types[0] == "category": plt.figure(figsize=(12, 6)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, j in enumerate(ims, start=1): plt.subplot(2, 5, i) im, cate = data[j] plt.title(label=cate) plt.imshow(X=im) elif data._target_types[0] == "binary-category": plt.figure(figsize=(12, 6)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, j in enumerate(ims, start=1): plt.subplot(2, 5, i) im, bincate = data[j] plt.title(label=bincate) plt.imshow(X=im) elif data._target_types[0] == "segmentation": plt.figure(figsize=(12, 12)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, j in enumerate(ims, start=1): im, seg = data[j] if 1 <= i and i <= 5: plt.subplot(4, 5, i) plt.imshow(X=im) plt.subplot(4, 5, i+5) plt.imshow(X=seg) if 6 <= i and i <= 10: plt.subplot(4, 5, i+5) plt.imshow(X=im) plt.subplot(4, 5, i+10) plt.imshow(X=seg) elif len(data._target_types) == 3: plt.figure(figsize=(12, 12)) plt.suptitle(t=main_title, y=1.0, fontsize=14) for i, j in enumerate(ims, start=1): im, (cate, bincate, seg) = data[j] if 1 <= i and i <= 5: plt.subplot(4, 5, i) plt.title(label=f"{cate}, {bincate}") plt.imshow(X=im) plt.subplot(4, 5, i+5) plt.imshow(X=seg) if 6 <= i and i <= 10: plt.subplot(4, 5, i+5) plt.title(label=f"{cate}, {bincate}") plt.imshow(X=im) plt.subplot(4, 5, i+10) plt.imshow(X=seg) plt.tight_layout(h_pad=3.0) plt.show() train_ims = (0, 1, 2, 50, 100, 150, 200, 250, 300, 350) test_ims = (0, 1, 2, 98, 198, 298, 398, 498, 598, 698) show_images(data=trainval_cate_data, ims=train_ims, main_title="trainval_cate_data") show_images(data=trainval_bincate_data, ims=train_ims, main_title="trainval_bincate_data") show_images(data=test_seg_data, ims=test_ims, main_title="test_seg_data") show_images(data=test_empty_data, ims=test_ims, main_title="test_empty_data") show_images(data=test_all_data, ims=test_ims, main_title="test_all_data")
Atas ialah kandungan terperinci OxfordIIITPet dalam PyTorch. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!