커피 한잔 사주세요😄
*메모:
RandomPerspective()는 아래와 같이 0개 이상의 이미지에 대해 원근 변환을 수행할 수 있습니다.
*메모:
from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import RandomPerspective from torchvision.transforms.functional import InterpolationMode randompers = RandomPerspective() randompers = RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=InterpolationMode.BILINEAR, fill=0) randompers # RandomPerspective(p=0.5, # distortion_scale=0.5, # interpolation=InterpolationMode.BILINEAR, # fill=0) randompers.distortion_scale # 0.5 randompers.p # 0.5 randompers.interpolation # <InterpolationMode.BILINEAR: 'bilinear'> randompers.fill # 0 origin_data = OxfordIIITPet( root="data", transform=None # transform=RandomPerspective(distortion_scale=0) # transform=RandomPerspective(p=0) ) dis02p1_data = OxfordIIITPet( root="data", transform=RandomPerspective(distortion_scale=0.2, p=1) ) dis06p1_data = OxfordIIITPet( root="data", transform=RandomPerspective(distortion_scale=0.6, p=1) ) dis1p1_data = OxfordIIITPet( root="data", transform=RandomPerspective(distortion_scale=1, p=1) ) p1_data = OxfordIIITPet( root="data", transform=RandomPerspective(p=1) ) p05_data = OxfordIIITPet( root="data", transform=RandomPerspective(p=0.5) ) p1fillgray_data = OxfordIIITPet( root="data", transform=RandomPerspective(p=1, fill=150) ) p1fillpurple_data = OxfordIIITPet( root="data", transform=RandomPerspective(p=1, fill=[160, 32, 240]) ) 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.xticks(ticks=[]) plt.yticks(ticks=[]) plt.tight_layout() plt.show() show_images1(data=origin_data, main_title="origin_data") show_images1(data=dis02p1_data, main_title="dis02p1_data") show_images1(data=dis06p1_data, main_title="dis06p1_data") show_images1(data=dis1p1_data, main_title="dis1p1_data") show_images1(data=p1_data, main_title="p1_data") show_images1(data=p05_data, main_title="p05_data") show_images1(data=p1fillgray_data, main_title="p1fillgray_data") show_images1(data=p1fillpurple_data, main_title="p1fillpurple_data") # ↓ ↓ ↓ ↓ ↓ ↓ The code below is identical to the code above. ↓ ↓ ↓ ↓ ↓ ↓ def show_images2(data, main_title=None, d=0.5, prob=0.5, f=0): 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) rp = RandomPerspective(distortion_scale=d, p=prob, fill=f) # Here plt.imshow(X=rp(im)) # Here plt.xticks(ticks=[]) plt.yticks(ticks=[]) plt.tight_layout() plt.show() show_images2(data=origin_data, main_title="origin_data", d=0) show_images2(data=origin_data, main_title="dis02p1_data", d=0.2, prob=1) show_images2(data=origin_data, main_title="dis06p1_data", d=0.6, prob=1) show_images2(data=origin_data, main_title="dis1p1_data", d=1, prob=1) show_images2(data=origin_data, main_title="p1_data", prob=1) show_images2(data=origin_data, main_title="p05_data", prob=0.5) show_images2(data=origin_data, main_title="p1fillgray_data", prob=1, f=150) show_images2(data=origin_data, main_title="p1fillpurple_data", prob=1, f=[160, 32, 240])
위 내용은 PyTorch의 RandomPerspective의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!