Pytorch中函数torchvision总结

版权声明:如要转载,请标明最初的转载链接 https://blog.csdn.net/weixin_36411839/article/details/82720642

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

transform = transforms.Compose([
transforms.Resize(256),
transforms.RandomCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.496],[0.229, 0.224, 0.225])
])

总结一般常用的类:
接下来介绍transforms中的函数

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

Normalize:正则化

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]
将numpy格式的图像数据转换为torch的FloatTensor格式,注意同时要转换维度。

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:随机改变图像的亮度对比度和饱和度

猜你喜欢

转载自blog.csdn.net/weixin_36411839/article/details/82720642