請我喝杯咖啡☕
*備忘錄:
RandomVerticalFlip() 可以垂直翻轉零個或多個影像,如下所示:
*備忘錄:
from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import RandomVerticalFlip RandomVerticalFlip() # RandomVerticalFlip(p=0.5) RandomVerticalFlip().p # 0.5 origin_data = OxfordIIITPet( root="data", transform=None ) trans100_data = OxfordIIITPet( root="data", transform=RandomVerticalFlip(p=1.0) ) trans50_data = OxfordIIITPet( root="data", transform=RandomVerticalFlip(p=0.5) ) import matplotlib.pyplot as plt def show_images(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_images(data=origin_data, main_title="origin_data") show_images(data=trans100_data, main_title="trans100_data") show_images(data=trans50_data, main_title="trans50_data")
from torchvision.datasets import OxfordIIITPet from torchvision.transforms.v2 import RandomVerticalFlip my_data = OxfordIIITPet( root="data", transform=None ) import matplotlib.pyplot as plt def show_images(data, main_title=None, prob=0.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) rvf = RandomVerticalFlip(p=prob) plt.imshow(X=rvf(im)) plt.xticks(ticks=[]) plt.yticks(ticks=[]) plt.tight_layout() plt.show() show_images(data=my_data, main_title="origin_data") show_images(data=my_data, main_title="trans100_data", prob=1.0) show_images(data=my_data, main_title="trans50_data", prob=0.5)
以上是PyTorch 中的隨機垂直翻轉的詳細內容。更多資訊請關注PHP中文網其他相關文章!