TenCrop
功能:在图像的上下左右以及中心裁剪出尺寸为size的5张图片,在这五张图片上进行水平或者垂直镜像获得10张图片;
transform_test = transforms.Compose([
transforms.TenCrop(cut_size),
transforms.Lambda(lambda crops: torch.stack([transforms.ToTensor()(crop) for crop in crops])),
])
img = Image.fromarray(img) #转化成PIL文件
inputs = transform_test(img) #transform
ncrops, c, h, w = inputs.shape
for i in range(ncrops):
img_=inputs[i]
img_=img_.transpose(0,2).transpose(0,1)
print(np.shape(img_))
img_ = np.array(img_) * 255
if img_.shape[2] == 3:
img_ = Image.fromarray(img_.astype('uint8')).convert('RGB')
plt.imshow(img_)
plt.show()
plt.pause(1)