Pytorch中图像预处理相关函数

这篇分类总结比较完整
数据处理是模型训练之前的必备的一步,在Pytorch的TORCHVISION.TRANSFORMS.TRANSFORMS包含下面一下图像处理的函数(transform中的函数主要是处理PIL格式图像):

  1. Compose
Args:
        transforms (list of ``Transform`` objects): list of transforms to compose.

"Composes several transforms together” 组合几种不同的变形方法

  1. ToTensor

Convert a PIL Image or numpy.ndarray to tensor. Converts a PIL Image or numpy.ndarray (H x W x C) in the range
[0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0]。将PIL图像或者numpy.ndarry类型数据转成tensor.

  1. ToPILImage

Convert a tensor or an ndarray to PIL Image.
Converts a torch.*Tensor of shape C x H x W or a numpy ndarray of shape H x W x C to a PIL Image while preserving the value range.

  1. Normalize 有参数(mean,std)
    处理的数据类型是tensor类型

Normalize a tensor image with mean and standard deviation.

Args:
        mean (sequence): Sequence of means for each channel.
        std (sequence): Sequence of standard deviations for each channel.

Given mean: (M1,...,Mn) and std: (S1,..,Sn) for n channels, this transform will normalize each channel of the input torch.*Tensor i.e. input[channel] = (input[channel] - mean[channel]) / std[channel]

  1. Resize

Resize the input PIL Image to the given size,默认采用PIL.Image.BILINEAR插值法。

Args:
        size (sequence or int): Desired output size. If size is a sequence like
            (h, w), output size will be matched to this. If size is an int,
            smaller edge of the image will be matched to this number.
            i.e, if height > width, then image will be rescaled to
            (size * height / width, size)
        interpolation (int, optional): Desired interpolation. Default is
            ``PIL.Image.BILINEAR``
  1. Scale

推荐换成Resize

  1. CenterCrop 参数(目标尺寸)

Crops the given PIL Image at the center
Args:
size (sequence or int): Desired output size of the crop. If size is an
int instead of sequence like (h, w), a square crop (size, size) is
made

  1. Pad

Pad the given PIL Image on all sides with the given “pad” value
Args:
padding (int or tuple):
fill (int or tuple):
padding_mode (str):

  1. Lambda

Apply a user-defined lambda as a transform
Args:
lambd (function): Lambda/function to be used for transform.

  1. RandomTransforms

Base class for a list of transformations with randomness
Args:
transforms (list or tuple): list of transformations

  1. RandomApply

Apply randomly a list of transformations with a given probability
Args:
transforms (list or tuple): list of transformations
p (float): probability

  1. RandomOrder

Apply a list of transformations in a random order

  1. RandomChoice

Apply single transformation randomly picked from a list

  1. RandomCrop

Crop the given PIL Image at a random location.

Args:
        size (sequence or int)
        padding (int or sequence, optional):
        pad_if_needed (boolean)
        fill
        padding_mode
  1. RandomHorizontalFlip

Horizontally flip the given PIL Image randomly with a given probability.

 Args:
        p (float): probability of the image being flipped. Default value is 0.5
  1. RandomVerticalFlip

Verticallly flip the given PIL Image randomly with a given probability.

 Args:
        p (float): probability of the image being flipped. Default value is 0.5
  1. RandomPerspective

Performs Perspective transformation of the given PIL Image randomly with a given probability.

  1. RandomResizedCrop

Crop the given PIL Image to random size and aspect ratio

  1. RandomSizedCrop

废弃

  1. FiveCrop

Crop the given PIL Image into four corners and the central crop

  1. TenCrop

Five Crop后翻转(默认是水平翻转)

  1. LinearTransformation

Transform a tensor image with a square transformation matrix and a mean_vector computed
offline

  1. ColorJitter

Randomly change the brightness, contrast and saturation of an image.
args:brightness=0, contrast=0, saturation=0, hue=0

  1. RandomRotation

Rotate the image by angle
args:degrees, resample=False, expand=False, center=None

  1. RandomAffine

Random affine transformation of the image keeping center invariant
degrees, translate=None, scale=None, shear=None, resample=False, fillcolor=0

  1. Grayscale

Convert image to grayscale.
args:num_output_channels=1

  1. RandomGrayscale

Randomly convert image to grayscale with a probability of p (default 0.1)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值