日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Pytorch中图像预处理相关函数

發布時間:2025/1/21 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Pytorch中图像预处理相关函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這篇分類總結比較完整
數據處理是模型訓練之前的必備的一步,在Pytorch的TORCHVISION.TRANSFORMS.TRANSFORMS包含下面一下圖像處理的函數(transform中的函數主要是處理PIL格式圖像):

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

    "Composes several transforms together” 組合幾種不同的變形方法

  • 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.

  • 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.

  • 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]

  • 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``
  • Scale
  • 推薦換成Resize

  • 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

  • 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):

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

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

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

  • RandomOrder
  • Apply a list of transformations in a random order

  • RandomChoice
  • Apply single transformation randomly picked from a list

  • RandomCrop
  • Crop the given PIL Image at a random location.

    Args:size (sequence or int)padding (int or sequence, optional):pad_if_needed (boolean)fillpadding_mode
  • 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
  • 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
  • RandomPerspective
  • Performs Perspective transformation of the given PIL Image randomly with a given probability.

  • RandomResizedCrop
  • Crop the given PIL Image to random size and aspect ratio

  • RandomSizedCrop
  • 廢棄

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

  • TenCrop
  • Five Crop后翻轉(默認是水平翻轉)

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

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

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

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

  • Grayscale
  • Convert image to grayscale.
    args:num_output_channels=1

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

    總結

    以上是生活随笔為你收集整理的Pytorch中图像预处理相关函数的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。