커피 한잔 사주세요😄
*메모:
Resize()는 아래와 같이 0개 이상의 이미지 크기를 조정할 수 있습니다.
*메모:
from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import Resize from torchvision.transforms.functional import InterpolationMode resize = Resize(size=100) resize = Resize(size=100, interpolation=InterpolationMode.BILINEAR, max_size=None, antialias=True) resize # Resize(size=[100], # interpolation=InterpolationMode.BILINEAR, # antialias=True) resize.size # [100] resize.interpolation # <InterpolationMode.BILINEAR: 'bilinear'> print(resize.max_size) # None resize.antialias # True origin_data = OxfordIIITPet( root="data", transform=None ) p1000_data = OxfordIIITPet( root="data", transform=Resize(size=1000) # transform=Resize(size=[1000]) ) p100_data = OxfordIIITPet( root="data", transform=Resize(size=100) ) p50_data = OxfordIIITPet( root="data", transform=Resize(size=50) ) p10_data = OxfordIIITPet( root="data", transform=Resize(size=10) ) p100p180_data = OxfordIIITPet( root="data", transform=Resize(size=[100, 180]) ) p180p100_data = OxfordIIITPet( root="data", transform=Resize(size=[180, 100]) ) p100ms110_data = OxfordIIITPet( root="data", transform=Resize(size=100, max_size=110) ) import matplotlib.pyplot as plt def show_images1(data, main_title=None): plt.figure(figsize=(10, 5)) plt.suptitle(t=main_title, y=0.8, fontsize=14) for i, (im, _) in zip(range(1, 6), data): plt.subplot(1, 5, i) plt.imshow(X=im) plt.tight_layout() plt.show() show_images1(data=origin_data, main_title="origin_data") show_images1(data=p1000_data, main_title="p1000_data") show_images1(data=p100_data, main_title="p100_data") show_images1(data=p50_data, main_title="p50_data") show_images1(data=p10_data, main_title="p10_data") print() show_images1(data=origin_data, main_title="origin_data") show_images1(data=p100p180_data, main_title="p100p180_data") show_images1(data=p180p100_data, main_title="p180p100_data") print() show_images1(data=p100_data, main_title="p100_data") show_images1(data=p100ms110_data, main_title='p100ms110_data') # ↓ ↓ ↓ ↓ ↓ ↓ The code below is identical to the code above. ↓ ↓ ↓ ↓ ↓ ↓ def show_images2(data, main_title=None, s=None, ms=None): plt.figure(figsize=(10, 5)) plt.suptitle(t=main_title, y=0.8, fontsize=14) for i, (im, _) in zip(range(1, 6), data): plt.subplot(1, 5, i) if not s: s = im.size resize = Resize(size=s, max_size=ms) # Here plt.imshow(X=resize(im)) # Here plt.tight_layout() plt.show() show_images2(data=origin_data, main_title="origin_data") show_images2(data=origin_data, main_title="p1000_data", s=1000) show_images2(data=origin_data, main_title="p100_data", s=100) show_images2(data=origin_data, main_title="p50_data", s=50) show_images2(data=origin_data, main_title="p10_data", s=10) print() show_images2(data=origin_data, main_title="origin_data") show_images2(data=origin_data, main_title="p100p180_data", s=[100, 180]) show_images2(data=origin_data, main_title="p180p100_data", s=[180, 100]) print() show_images2(data=origin_data, main_title="p100_data", s=100) show_images2(data=origin_data, main_title="p100ms110_data", s=100, ms=110)
위 내용은 PyTorch에서 크기 조정의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!