pytorch数据增强方法
啥都亿点点的研究生
这个作者很懒,什么都没留下…
展开
-
24、其他api函数以及两种自动增强的方法
24、针对tensor操作,随机选择矩形区域删除torchvision.transforms.RandomErasing(p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=False)25、针对tensor操作,归一化图片,给定均值和方差torchvision.transforms.Normalize(mean, std, inplace=False)26、给定tensor数据格式进行改变torchvision.transf原创 2022-04-03 08:44:34 · 372 阅读 · 0 评论 -
23、随机均衡器 transforms.RandomEqualize(p=0.5)
transforms.RandomInvert(p=0.5)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.RandomInvert(p=0.8)(img0)axs = plt.f原创 2022-04-03 08:44:43 · 787 阅读 · 0 评论 -
22、随机自动对比 transforms.RandomAutocontrast(p=0.5)
transforms.RandomAutocontrast(p=0.5)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.RandomAutocontrast(p=0.1)(img0)原创 2022-04-03 08:45:36 · 755 阅读 · 0 评论 -
21、随机调整锐度 transforms.RandomAdjustSharpness()
transforms.RandomAdjustSharpness(sharpness_factor, p=0.5) sharpness_factor:需要调整多少锐度。可以是任何非负数 0-模糊,1-原图,2-锐度提高两倍import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.ope原创 2022-04-03 08:44:51 · 1348 阅读 · 0 评论 -
20、日光化 transforms.RandomSolarize(threshold, p=0.5)
transforms.RandomSolarize(threshold, p=0.5) 通过反转阈值以上的所有像素值,以给定的概率随机对图像进行日光化import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=t原创 2022-04-02 10:52:07 · 987 阅读 · 0 评论 -
19、随机后处理 transforms.RandomPosterize(bits, p=0.5)
transforms.RandomPosterize(bits, p=0.5)通过减少每个颜色通道的位数,以给定的概率随机对图像进行后处理。 bits :每个通道要保留的位数(0-import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-0000原创 2022-04-02 10:52:00 · 742 阅读 · 0 评论 -
18、随机反转 transforms.RandomInvert(p=0.5)
transforms.RandomInvert(p=0.5)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.RandomInvert(p=0.8)(img0)axs = plt.f原创 2022-04-02 10:51:55 · 588 阅读 · 0 评论 -
17、高斯模糊 transforms.GaussianBlur()
transforms.GaussianBlur(kernel_size, sigma=(0.1, 2.0)) kernel_size:高斯卷积核大小 sigma:标准差(min,max)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-.原创 2022-04-02 10:51:48 · 5748 阅读 · 1 评论 -
16、将给定的图像裁剪成四个角,中央裁剪加上这些角的翻转版本(默认情况下使用水平翻转)。 transforms.TenCrop(size, vertical_flip=False)
transforms.TenCrop(size, vertical_flip=False) vertical_flip:是否翻转import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.T.原创 2022-04-02 10:51:40 · 367 阅读 · 0 评论 -
15、调整尺寸 transforms.Resize()
transforms.Resize(size, interpolation=<InterpolationMode.BILINEAR: 'bilinear'>, max_size=None, antialias=None) antialias :如果img是PIL图像,则忽略该标志,并始终为True。如果img是张量,则默认情况下该标志为Falseimport torchvision.transforms as transformfrom PIL import Imageimport ma原创 2022-04-02 10:51:34 · 5194 阅读 · 1 评论 -
14、随机垂直翻转 transforms.RandomVerticalFlip(p=0.5)
transforms.FiveCrop(size) size-输入为图片的长,宽,可单值或(h,w)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.RandomVerticalFl原创 2022-04-02 10:51:26 · 1162 阅读 · 1 评论 -
13、随机旋转 transforms.RandomRotation()
transforms.RandomRotation(degrees, interpolation=<InterpolationMode.NEAREST: 'nearest'>, expand=False, center=None, fill=0, resample=None)expand:可选扩展标志。如果为true,则扩展输出,使其足够大,以容纳整个旋转图像。如果为false或省略,请使输出图像与输入图像大小相同。import torchvision.transforms as tran原创 2022-04-02 10:51:13 · 13320 阅读 · 0 评论 -
12、裁剪图像的随机部分,并将其调整为给定大小。 transforms.RandomResizedCrop()
transforms.RandomResizedCrop(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=<InterpolationMode.BILINEAR: 'bilinear'>)scale:在调整大小之前,指定裁剪的随机区域的下限和上限。比例是根据原始图像的面积定义的。ratio:调整大小之前,裁剪的随机纵横比的上下限import torchvision.transforms as原创 2022-04-02 10:51:04 · 837 阅读 · 0 评论 -
11、随机视角变化 transforms.RandomPerspective()
transforms.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=<InterpolationMode.BILINEAR: 'bilinear'>, fill=0)distortion_scale:角度的倾斜值,取值(0,1)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pl原创 2022-04-02 10:50:52 · 2819 阅读 · 0 评论 -
10、随机图片水平翻转 transforms.RandomHorizontalFlip(p=0.5)
transforms.RandomHorizontalFlip(p=0.5)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.RandomHorizontalFlip(p=0.8)(i原创 2022-04-01 09:15:55 · 10922 阅读 · 0 评论 -
9、随机图片灰度化 transforms.RandomGrayscale(p=0.1)
transforms.RandomGrayscale(p=0.1)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.RandomGrayscale(p=0.8)(img0)axs =原创 2022-04-01 09:13:43 · 2140 阅读 · 0 评论 -
8、随机裁剪 transforms.RandomCrop()
transforms.RandomCrop(size, padding=None, pad_if_needed=False, fill=0, padding_mode='constant')size:期望随机裁剪之后输出的尺寸padding:填充边界的值,单个(int),两个([左/右,上/下]),四个(各个边界)pad_if_needed :bool值,避免数组越界fill:填充padding_mode :填充模式“constant”:利用常值进行填充“edge”:利用图像边缘像素点进行填充原创 2022-04-01 09:11:23 · 22599 阅读 · 0 评论 -
4、图片转为灰度图 transforms.Grayscale()
transforms.Grayscale()num_output_channels=1 or 3import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.Grayscale(3)(img0.原创 2022-04-01 08:57:57 · 6399 阅读 · 0 评论 -
7、随机应用给定概率的变换列表。 transforms.RandomApply()
transforms.RandomApply(transforms, p=0.5) transforms:给定变化的列表,类型:nn.MModuleList([])import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torch.nn as nntrans=nn.ModuleList([ transf原创 2022-04-01 09:05:20 · 2017 阅读 · 0 评论 -
6、随机仿射变化 transforms.RandomAffine()
transforms.RandomAffine(degrees, translate=None, scale=None, shear=None, interpolation=<InterpolationMode.NEAREST: 'nearest'>, fill=0, fillcolor=None, resample=None, center=None)degrees:可从中选择的度数范围。如果为非零数字,旋转角度从(-degrees,+degress),或者可设置为(min,max)tr原创 2022-04-01 09:03:00 · 11823 阅读 · 1 评论 -
5、边界填充 transforms.Pad(padding, fill=0, padding_mode=‘edge‘)
transforms.Pad(padding, fill=0, padding_mode='edge')padding:列表,元素个数为1,2,4fill:int-单值 or (r,g,b)padding_mode:填充方式“constant”:利用常值进行填充“edge”:利用图像边缘像素点进行填充“reflect”:利用反射的方式进行填充[1, 2, 3, 4] 》[3, 2, 1, 2, 3, 4, 3, 2]“symmetric”:对称填充方法[1, 2, 3, 4] 》》[2, 1,原创 2022-04-01 08:59:35 · 4858 阅读 · 0 评论 -
3、图片裁剪成固定尺寸5份 transforms.FiveCrop(size)
transforms.FiveCrop(size) size-输入为图片的长,宽,可单值或(h,w)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.FiveCrop((160,16原创 2022-04-01 08:55:35 · 748 阅读 · 0 评论 -
1、随机中心裁剪 transforms.CenterCrop(size)
transforms.CenterCrop(size)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.CenterCrop((32,32))(img0) #随机中心裁剪img2=原创 2022-04-01 08:52:08 · 4390 阅读 · 0 评论 -
2、图片亮度,对比度,饱和度,明度调整 transforms.ColorJitter(brightness=0, contrast=0, saturation=0, hue=0)
transforms.CenterCrop(size)import torchvision.transforms as transformfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npimport torchimg0=Image.open('lin-xiao-xun-000003.jpg')img1=transform.CenterCrop((32,32))(img0) #随机中心裁剪img2=原创 2022-04-01 08:46:55 · 4322 阅读 · 1 评论