Pytorch torchvision.transforms模块使用

torchvision.transforms模块构成

torchvision.transforms模块包含如下类:

__all__ = ["Compose", "ToTensor", "PILToTensor", "ConvertImageDtype", "ToPILImage", "Normalize", "Resize", "Scale",
           "CenterCrop", "Pad", "Lambda", "RandomApply", "RandomChoice", "RandomOrder", "RandomCrop",
           "RandomHorizontalFlip", "RandomVerticalFlip", "RandomResizedCrop", "RandomSizedCrop", "FiveCrop", "TenCrop",
           "LinearTransformation", "ColorJitter", "RandomRotation", "RandomAffine", "Grayscale", "RandomGrayscale",
           "RandomPerspective", "RandomErasing", "GaussianBlur", "InterpolationMode", "RandomInvert", "RandomPosterize",
           "RandomSolarize", "RandomAdjustSharpness", "RandomAutocontrast", "RandomEqualize"]

Compose()

将几个变换组合在一起。
例如:

             transforms.Compose([
             transforms.CenterCrop(10),
             transforms.PILToTensor(),
             transforms.ConvertImageDtype(torch.float),
       ])

ToTensor()

转换范围[0,255]的PIL图像或numpy.ndarray (H x W x C)成形状C x H x W,范围[0.0,1.0]的FloatTensor

PILToTensor()

将PIL Image 转换为相同类型的张量

ToPILImage()

将tensor或ndarray转换成到PIL图像

Normalize(mean, std)

对数据按通道进行标准化,即先减均值,再除以标准差

Resize()

调整输入图像的大小为给定的大小

Scale()

不赞成使用这种转换,而是使用Resize

CenterCrop()

裁剪给定图像的中心.。如果图像大小小于输出大小,则图像用0填充,然后在中心裁剪。

Pad()

给定的"Pad "值填充给定图像的所有边。

RandomCrop()

依据给定的 size 随机裁剪

RandomResizedCrop

随机大小,随机长宽比裁剪原始图片,最后将图片 resize 到设定好的 size

RandomAffine()

仿射变换

RandomRotation()

随机旋转一定角度

RandomHorizontalFlip()

对 PIL 图片进行水平翻转

Grayscale()

将图片转换为灰度图

ColorJitter()

修改修改亮度、对比度和饱和度

RandomOrder()

将 transforms 中的操作顺序随机打乱

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值