pytorch中transforms.Compose()函数

transforms函数解析:

self.norm = transforms.Compose([

            transforms.ToTensor(),

            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),

        ])

torchvision.transforms是pytorch中的图像预处理包。一般用Compose把多个步骤整合到一起:

比如说:

transforms.Compose([

transforms.CenterCrop(10),

transforms.ToTensor(),

])

扫描二维码关注公众号,回复: 9455870 查看本文章

这样就把两个步骤整合到了一起。

 

接下来介绍transforms中的函数:

Resize:把给定的图片resize到given size

Normalize:Normalized an tensor image with mean and standard deviation

ToTensor:convert a PIL image to tensor (H*W*C) in range [0,255] to a torch.Tensor(C*H*W) in the range [0.0,1.0]

ToPILImage: convert a tensor to PIL image

Scale:目前已经不用了,推荐用Resize

CenterCrop:在图片的中间区域进行裁剪

RandomCrop:在一个随机的位置进行裁剪

RandomHorizontalFlip:以0.5的概率水平翻转给定的PIL图像

RandomVerticalFlip:以0.5的概率竖直翻转给定的PIL图像

RandomResizedCrop:将PIL图像裁剪成任意大小和纵横比

Grayscale:将图像转换为灰度图像

RandomGrayscale:将图像以一定的概率转换为灰度图像

FiceCrop:把图像裁剪为四个角和一个中心

TenCrop

Pad:填充

ColorJitter:随机改变图像的亮度对比度和饱和度。

发布了191 篇原创文章 · 获赞 104 · 访问量 34万+

猜你喜欢

转载自blog.csdn.net/u013925378/article/details/103363232