🍅 写在前面
👨?🎓 博主介绍:大家好,这里是hyk写算法了吗,一枚致力于学习算法和人工智能领域的小菜鸟。
🔎个人主页:主页链接(欢迎各位大佬光临指导)
??近期专栏:机器学习与深度学习
???????????????????????LeetCode算法实例
torchvision.transforms.CenterCrop(size)
torchvision.transforms.RandomCrop(size, padding=None,
pad_tf_needed=False, fill=0, padding_mode=‘constant’)
torchvision.transforms.RandomResizedCrop(size, scale=(0.08, 1.0),
ratio=(3/4, 4/3), interpolation=2)
torchvision.transforms.FiveCrop(size)
torchvision.transforms.TenCrop(size, vertical_flip=False)
# torchvision.transforms.CenterCrop
transforms = T.Compose([T.Resize(224),T.CenterCrop(224),T.ToTensor()]) # Resize:缩放
cat_t = transforms(cat) # 传入transforms中的数据是PIL数据,lena_t为tensor
cat_t.shape # 3*224*224 ; 当T.CenterCrop()的参数大于T.Resize()的参数时,周围用0填充
to_pil(cat_t)
# torchvision.transforms.RandomCrop
transforms = T.Compose([T.Resize(224),T.RandomCrop(224, padding=(16, 64)),T.ToTensor()]) # Resize:缩放
cat_t = transforms(cat) # 传入transforms中的数据是PIL数据,lena_t为tensor
cat_t.shape # 3*224*224 ; 当T.CenterCrop()的参数大于T.Resize()的参数时,周围用0填充
to_pil(cat_t)
torchvision.transforms.RandomHorizontalFlip(p=0.5)
torchvision.transforms.RandomVerticalFlip(p=0.5)
torchvision.transforms.RandomRotation(degrees, resample=False,
expand=False, center=None)
torchvision.transforms.Pad(padding, fill=0, padding_mode=‘constant’)
torchvision.transforms.ColorJitter(brightness=0, contrast=0,
saturation=0, hue=0)
torchvision.transforms.Grayscale(num_output_channels=1)
torchvision.transforms.RandomGrayscale(p=0.1)
torchvision.transforms.RandomAffine(degrees, translate=None,
scale=None, shear=None, resample=0, fillcolor=0)
torchvision.transforms.RandomErasing(p=0.5, scale=(0.02, 0.33),
ratio=(0.3, 3.3), value=0, inplace=False)
torchvision.transforms.Lambda(lambd)
- 功能: 用户自定义lambda方法
- lambd: lambda匿名函数
例如:transforms.Lambda(lambda crops: torch.stack([transforms.Totensor()(crop) for crop in crops]))
自定义transforms要素:
1、仅接收一个参数,返回一个参数
2、注意上下游的输出与输入
class Compose(object):
def __call__(self, img):
for t in transforms:
img = t(img)
return img
通过类实现多参数传入:
class YourTransforms(object):
def __init__(self, transforms):
self.transforms = transforms
def __call__(self, img):
for t in self.transforms:
img = t(img)
return img
椒盐噪声又称为脉冲噪声,是一种随机出现的白点或者黑点,白点称为盐噪声,黑色为椒噪声。
信噪比(Signal-Noise Rate,SNR)是衡量噪声的比例,图像中为图像像素的占比。
class AddPepperNoise(object):
def __init__(self, snr, p):
self.snr = snr
self.p = p
def __call__(self, img):
# 添加椒盐噪声具体实现过程
img = None
return img
a. transforms.CenterCrop
b. transforms.RandomCrop
c. transforms.RandomResizedCrop
d. transforms.FiveCrop
e. transforms.TenCrop
a. transforms.RandomHorizontalFlip
b. transforms.RandomVerticalFlip
c. transforms.RandomRotation
a. transforms.Pad
b. transforms.ColorJitter
c. transforms.Grayscale
d. transforms.RandomGrayscale
e. transforms.RandomAffine
f. transforms.LinearTransformation
g. transforms.RandomErasing
h. transforms.Lambda
i. transforms.Resize
j. transforms.Totensor
k. transforms.Normalize
a. transforms.RandomChoice
b. transforms.RandomApply
c. transforms.RandomOrder