「Deep Learning」理解PyTorch中的「torchvision.transforms」

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dgyuanshaofeng/article/details/84076608

QQ Group: 428014259
Sina Weibo:小锋子Shawn
Tencent E-mail:[email protected]
http://blog.csdn.net/dgyuanshaofeng/article/details/84076608

阅读的是PyTorch 0.4.1

0 torchvision.transforms

该类用于图像变换,以进行数据扩充,缓解深度模型过拟合问题。目前,其实有大量的专门的数据扩充Python软件包,不过在不同框架中,会内置一些常见的操作。如果,处理的数据是医学图像,比如CT和MR,实际上,数据归一化到标准范围,效果可能会更好。因为上述的粗暴图像变换,会增加深度模型对数据的理解/学习,对拟合过程进行了干扰,使得模型难以稳定训练。

基本使用就是利用torchvision.transforms.Compose对几种图像变换进行打包,组成复合变换,如下面:

 transforms.Compose([
 	 transforms.CenterCrop(10),
 	 transforms.ToTensor(),
])

将中心裁剪和变换为Tensor两种操作进行了打包。Compose接收列表list,该列表由transforms的对象构成。

1 Transforms on PIL Image

在PIL Image上进行图像变换。

torchvision.transforms.CenterCrop,对图像进行中心裁剪。如果仅给int参数,那么将裁剪正方形图像分块;如果给出高和宽(h,w),那么将裁剪矩形图像分块。

torchvision.transforms.ColorJitter, 对图像进行亮度(brightness), 对比度(contrast), 饱和度(saturation)和色调(hue)随机调节。

torchvision.transforms.FiveCrop,对图像进行四角好中心裁剪,获得5张图像,通常用于分类的测试过程。

torchvision.transforms.Grayscale,将彩色图像转换为灰度图像,可以指定输出灰度图像的通道数。

torchvision.transforms.LinearTransformation,根据仿射矩阵进行变换,用于对数据进行白化(去相关)处理。

torchvision.transforms.Pad,对图像进行填充。

torchvision.transforms.RandomAffine,对图像进行随机仿射变换。

torchvision.transforms.RandomApply,给定概率,对列表中的操作进行随机使用。

torchvision.transforms.RandomChoice,对列表中的操作选择一个,进行使用。

torchvision.transforms.RandomCrop,随机裁剪图像分块。

torchvision.transforms.RandomGrayscale,图像在给定概率下,变换为灰度图像。

torchvision.transforms.RandomHorizontalFlip,图像进行左右/水平随机翻转。

torchvision.transforms.RandomVerticalFlip,图像进行上下/竖直随机翻转。

torchvision.transforms.RandomOrder,对列表的操作进行随机排序并使用。

torchvision.transforms.RandomResizedCrop,对图像进行不同大小和高宽比裁剪。

torchvision.transforms.RandomRotation,对图像进行随机旋转。

torchvision.transforms.Resize,对图像进行resize。

torchvision.transforms.TenCrop,对图像的四角和中心进行裁剪,进行左右翻转之后,再进行四角和中心进行裁剪,共10张图像。

2 Transforms on torch.*Tensor

torchvision.transforms.Normalize,对张量图像进行均值和标准差归一化,即标准正态分布化。

3 Conversion Transforms

torchvision.transforms.ToPILImage,将张量或多维数组,转换为PIL Image。

torchvision.transforms.ToTensor,将多维数组或PIL Image,转换为张量。

4 Generic Transforms

自定义图像变换

5 Functional Transforms

函数式图像变换,跟上面的类似。
torchvision.transforms.functional.adjust_brightness
torchvision.transforms.functional.adjust_contrast
torchvision.transforms.functional.adjust_gamma
torchvision.transforms.functional.adjust_hue
torchvision.transforms.functional.adjust_saturation
torchvision.transforms.functional.affine
torchvision.transforms.functional.crop
torchvision.transforms.functional.five_crop
torchvision.transforms.functional.hflip
torchvision.transforms.functional.normalize
torchvision.transforms.functional.pad
torchvision.transforms.functional.resize
torchvision.transforms.functional.resized_crop
torchvision.transforms.functional.rotate
torchvision.transforms.functional.ten_crop
torchvision.transforms.functional.to_grayscale
torchvision.transforms.functional.to_pil_image
torchvision.transforms.functional.to_tensor
torchvision.transforms.functional.vflip

猜你喜欢

转载自blog.csdn.net/dgyuanshaofeng/article/details/84076608
今日推荐