*Memos:
- My post explains RandomHorizontalFlip().
- My post explains RandomRotation().
- My post explains RandomAffine().
- My post explains RandomPerspective().
- My post explains OxfordIIITPet().
RandomVerticalFlip() can flip zero or more images vertically as shown below:
*Memos:
- The 1st argument for initialization is
p
(Optional-Default:0.5
-Type:int
orfloat
): *Memos:- It’s the probability of whether each image is flipped or not.
- It must be
0 <= x <= 1
.
- The 1st argument is
img
(Required-Type:PIL Image
ortensor
(int
,float
,complex
orbool
)): *Memos:- The 0D or more D of zero or more elements can be set to it.
- Don’t use
img=
.
-
v2
is recommended to use according to V1 or V2? Which one should I use?.
from torchvision.datasets import OxfordIIITPet
from torchvision.transforms.v2 import RandomVerticalFlip
randomverticalflip = RandomVerticalFlip()
randomverticalflip = RandomVerticalFlip(p=0.5)
randomverticalflip
# RandomVerticalFlip(p=0.5)
randomverticalflip.p
# 0.5
origin_data = OxfordIIITPet(
root="data",
transform=None
# transform=RandomVerticalFlip(p=0) )
p1_data = OxfordIIITPet(
root="data",
transform=RandomVerticalFlip(p=1)
)
p05_data = OxfordIIITPet(
root="data",
transform=RandomVerticalFlip(p=0.5)
)
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=p1_data, main_title="p1_data")
show_images1(data=p05_data, main_title="p05_data")
# ↓ ↓ ↓ ↓ ↓ ↓ The code below is identical to the code above. ↓ ↓ ↓ ↓ ↓ ↓ def show_images2(data, main_title=None, prob=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_images2(data=origin_data, main_title="origin_data")
show_images2(data=origin_data, main_title="p1_data", prob=1)
show_images2(data=origin_data, main_title="p1_data", prob=0.5)
Enter fullscreen mode Exit fullscreen mode
© 版权声明
THE END
暂无评论内容