当前位置:网站首页>【pytorch】|transforms.FiveCrop

【pytorch】|transforms.FiveCrop

2022-07-27 16:33:00 rrr2

Common image transformation
There are four categories to summarize here

tailoring (Crop)

Center cut :transforms.CenterCrop
Random cutting :transforms.RandomCrop
Random aspect ratio tailoring :transforms.RandomResizedCrop
Top, bottom, left and right center cut :transforms.FiveCrop
Cut the top, bottom, left and right center, and then flip ,transforms.TenCrop

Flip and rotate (Flip and Rotation)

According to probability p Flip horizontal :transforms.RandomHorizontalFlip(p=0.5)
According to probability p Flip vertically :transforms.RandomVerticalFlip(p=0.5)
Random rotation :transforms.RandomRotation

Image transformation (resize)transforms.Resize

Standardization :transforms.Normalize
To tensor, And normalized to [0-1]:transforms.ToTensor
fill :transforms.Pad
Change the brightness 、 Contrast and saturation :transforms.ColorJitter
Go to grayscale :transforms.Grayscale
linear transformation :transforms.LinearTransformation()
Affine transformation :transforms.RandomAffine
According to probability p Turn to grayscale :transforms.RandomGrayscale
Convert data to PILImage:transforms.ToPILImage
take lambda Apply as transform :transforms.Lambda

Yes transforms operation , Make data enhancement more flexible

From a given series of transforms Choose one of them to operate :transforms.RandomChoice(transforms),
Give me a transform Plus the probability , Operate according to probability :transforms.RandomApply(transforms, p=0.5)
take transforms The operations in are randomly disrupted :

import torchvision
import torchvision.transforms as transform
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import torch
img0=Image.open('imge.png')
resize = torchvision.transforms.Resize((224,224))
img0_r=resize(img0)
img1=transform.FiveCrop((112,112))(img0_r)
axs = plt.figure().subplots(1, 6)
axs[0].imshow(img0_r);axs[0].set_title('src');axs[0].axis('off')
axs[1].imshow(img1[0]);axs[1].set_title('1');axs[1].axis('off')
axs[2].imshow(img1[1]);axs[2].set_title('2');axs[2].axis('off')
axs[3].imshow(img1[2]);axs[3].set_title('3');axs[3].axis('off')
axs[4].imshow(img1[3]);axs[4].set_title('4');axs[4].axis('off')
axs[5].imshow(img1[4]);axs[5].set_title('5');axs[5].axis('off')
plt.show()

 Insert picture description here

原网站

版权声明
本文为[rrr2]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/199/202207151634233575.html