train_transforms = transforms.Compose([
transforms.Resize((224, 224)),
# 1.CenterCrop
# transforms.CenterCrop(512), # 196、512
# 2.RandomCrop
# transforms.RandomCrop(224,padding=16),
# transforms.RandomCrop(224,padding=(16, 64)),
# transforms.RandomCrop(224, padding=16, fill=(255,0,0)),
# transforms.RandomCrop(512,pad_if_needed=True),
# transforms.RandomCrop(224,padding=64,padding_mode="edge"),
# transforms.RandomCrop(224,padding=64,padding_mode="reflect"),
# transforms.RandomCrop(224,padding=64,padding_mode="symmetric"),
# transforms.RandomCrop(1024,padding=1024,padding_mode="symmetric"),
# 3.RandomResizeCrop
# transforms.RandomResizedCrop(size=224, scale=(0.08, 1)),
# transforms.RandomResizedCrop(size=224, scale=(0.5,0.5)),
# 翻转
# 4.HorizontalFlip
# transforms.RandomHorizontalFlip(p=1),
# 5.VerticalFlip
# transforms.RandomVerticalFlip(p=0.5),
# 旋转
# 6.RandomRotation
# transforms.RandomRotation(90),
# transforms.RandomRotation((90), expand=True), # 保图填充
# transforms.RandomRotation(30, center=(0, 0)), # (0, 0)左上角为旋转中心
# transforms.RandomRotation(30, center=(0, 0), expand=True),
# 7.pad
# transforms.Pad(padding=32,fill=(255,0,0),padding_mode="constant"),
# transforms.Pad(padding=(8,64), fill=(255,0,0), padding_mode="constant"),
# transforms.Pad(padding=(8,16,32,64),fill=(255,0,0),padding_mode="constant"),
# transforms.Pad(padding=(8,16,32,64),padding_mode="symmetric"),
# 8.色彩变换(ColoJitter)
# transforms.ColorJitter(brightness=0.1), # 亮度:越小越亮
# transforms.ColorJitter(contrast=1), # 对比度:升高图像会发灰
# transforms.ColorJitter(saturation=0.1), # 饱和度:升高图像会变暗淡
# transforms.ColorJitter(hue=0.3), # 色相
# 9.灰度变化(Grayscale)
# transforms.Grayscale(num_output_channels=1),
# transforms.RandomGrayscale(p=0.9),
# 10.仿射变换(包括:旋转、平移、缩放、错切、翻转)
# transforms.RandomAffine(degrees=30), # (-30,+30)之间进行中心旋转
# 平移,范围左右(-0.2w,+0.2w),上下(-0.2w,+0.2w),四个边先填充,然后裁剪
# transforms.RandomAffine(degrees=0, translate=(0.2, 0.2), fillcolor=(255,0,0)),
# transforms.RandomAffine(degrees=0, scale=(0.7,0.7)), # 缩放
# transforms.RandomAffine(degrees=0, shear=(0,0,0,45)), # 设置y轴进行错切
# transforms.RandomAffine(degrees=0, shear=(0,90,0,0)), # 设置x轴进行错切
# transforms.RandomAffine(degrees=0, shear=90), # 设置x轴进行错切
# 11.随机遮挡 ==> 这里直接对tensor进行操作,之前的方法都是在PIL.image上进行计算的
# transforms.ToTensor(), # 注意要注释掉后面Totensor和Normalize.
# transforms.RandomErasing(p=1, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=(254/255, 0, 0)), # 纯色填充
# transforms.RandomErasing(p=1, scale=(0.02, 0.33), ratio=(0.3, 3.3), value="1234"), # 实现任意像素块遮挡
# 组合
# 1.随机选择一种
# transforms.RandomChoice([transforms.RandomVerticalFlip(p=1),
# transforms.RandomHorizontalFlip(p=1)]),
# 2.依据概率p执行一组transforms操作
# transforms.RandomApply([transforms.RandomAffine(degrees=0, shear=45, fillcolor=(255, 0, 0)),
# transforms.Grayscale(num_output_channels=3)],
# p=0.5),
# 3.对一组transforms操作打乱顺序
transforms.RandomOrder([transforms.RandomRotation(15),
transforms.RandomAffine(degrees=0, translate=(0.01, 0.1), scale=(0.9, 1.1)),
transforms.Pad(padding=32)]),
transforms.ToTensor(), # 进行归一化
transforms.Normalize(norm_mean, norm_std) # 标准化
])
08-31
6050
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-19
1091
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-25