*Memos:
- My post explains OxfordIIITPet().
FiveCrop() can crop an image into 5 parts(Top-left, Top-right, bottom-left, bottom-right and center) as shown below:
*Memos:
- The 1st argument for initialization is
size
(Required-Type:int
ortuple/list
(int
) or size()): *Memos:- It's
[height, width]
. - It must be
1 <= x
. - A tuple/list must be the 1D with 1 or 2 elements.
- A single value(
int
ortuple/list
(int
)) means[size, size]
.
- It's
- The 1st argument is
img
(Required-Type:PIL Image
ortensor
(int
)): *Memos:- A tensor must be the 2D or 3D of one or more elements.
- 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 FiveCrop
fivecrop = FiveCrop(size=100)
fivecrop
# FiveCrop(size=(100, 100))
fivecrop.size
# (100, 100)
origin_data = OxfordIIITPet(
root="data",
transform=None
)
s500_394origin_data = OxfordIIITPet( # `s` is size.
root="data",
transform=FiveCrop(size=[500, 394])
# transform=FiveCrop(size=[600])
# transform=FiveCrop(size=[600, 600])
)
s300_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=300)
)
s200_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=200)
)
s100_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=100)
)
s50_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=50)
)
s10_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=10)
)
s200_300_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=[200, 300])
)
s300_200_data = OxfordIIITPet(
root="data",
transform=FiveCrop(size=[300, 200])
)
import matplotlib.pyplot as plt
def show_images1(fcims, main_title=None):
plt.figure(figsize=(10, 5))
plt.suptitle(t=main_title, y=0.8, fontsize=14)
titles = ['Top-left', 'Top-right', 'bottom-left',
'bottom-right', 'center']
for i, fcim in zip(range(1, 6), fcims):
plt.subplot(1, 5, i)
plt.title(label=titles[i-1], fontsize=14)
plt.imshow(X=fcim)
plt.tight_layout()
plt.show()
plt.figure(figsize=(7, 9))
plt.title(label="Origin_data", fontsize=14)
plt.imshow(X=origin_data[0][0])
show_images1(fcims=s500_394origin_data[0][0], main_title="s500_394origin_data")
show_images1(fcims=s300_data[0][0], main_title="s300_data")
show_images1(fcims=s200_data[0][0], main_title="s200_data")
show_images1(fcims=s100_data[0][0], main_title="s100_data")
show_images1(fcims=s50_data[0][0], main_title="s50_data")
show_images1(fcims=s10_data[0][0], main_title="s10_data")
show_images1(fcims=s200_300_data[0][0], main_title="s200_300_data")
show_images1(fcims=s300_200_data[0][0], main_title="s300_200_data")
# ↓ ↓ ↓ ↓ ↓ ↓ The code below is identical to the code above. ↓ ↓ ↓ ↓ ↓ ↓
def show_images2(im, main_title=None, s=None):
plt.figure(figsize=(10, 5))
plt.suptitle(t=main_title, y=0.8, fontsize=14)
titles = ['Top-left', 'Top-right', 'bottom-left',
'bottom-right', 'center']
if not s:
s = [im.size[1], im.size[0]]
fc = FiveCrop(size=s) # Here
for i, fcim in zip(range(1, 6), fc(im)):
plt.subplot(1, 5, i)
plt.title(label=titles[i-1], fontsize=14)
plt.imshow(X=fcim) # Here
plt.tight_layout()
plt.show()
plt.figure(figsize=(7, 9))
plt.title(label="Origin_data", fontsize=14)
plt.imshow(X=origin_data[0][0])
show_images2(im=origin_data[0][0], main_title="s500_394origin_data")
# show_images2(im=origin_data[0][0], main_title="s500_394origin_data",
# s=[500, 394])
show_images2(im=origin_data[0][0], main_title="s300_data", s=300)
show_images2(im=origin_data[0][0], main_title="s200_data", s=200)
show_images2(im=origin_data[0][0], main_title="s100_data", s=100)
show_images2(im=origin_data[0][0], main_title="s50_data", s=50)
show_images2(im=origin_data[0][0], main_title="s10_data", s=10)
show_images2(im=origin_data[0][0], main_title="s200_300_data", s=[200, 300])
show_images2(im=origin_data[0][0], main_title="s300_200_data", s=[300, 200])
Top comments (0)