TORCHVISION.TRANSFORMS包的用法

TORCHVISION.TRANSFORMS包中部分类的用法

  • CLASS torchvision.transforms.Compose(transforms)
    将需要进行变换的操作组合起来 例如

```python
>>> transforms.Compose([
>>>     transforms.CenterCrop(10),
>>>     transforms.ToTensor(),
>>> ])
  • CLASS torchvision.transforms.CenterCrop(size)
    在中心裁剪给定的PIL图像。参数size表示期望裁剪后的输出的大小。形式为(h,w)或者为一个整数int z(表示输出为(z,z))。

  • CLASS torchvision.transforms.RandomCrop(size, padding=None, pad_if_needed=False, fill=0, padding_mode=‘constant’)
    对给定的图像随机裁剪
    Parameters
    size (sequence or python:int)
    形式为(h,w)或者为一个整数int z(表示输出为(z,z))。
    padding (python:int or sequence, optional)
    默认无填充。如果提供长度为4的序列,则分别用它填充左边框、上边框、右边框和下边框。如果提供长度为2的序列,则分别用它填充左/右、上/下边界。
    pad_if_needed (boolean)
    如果图像小于期望的大小,它将填充图像以避免引发异常。因为裁剪是在填充之后完成的,所以填充看起来是随机偏移的。
    fill
    像素填充值为常数填充。默认值为0。如果一个长度为3的元组,则分别用于填充R、G、B通道。此值仅在padding_mode为常量时使用。
    padding_mode
    type of padding. Should be: constant, edge, reflect or symmetric. Default is constant.填充的形式设置

  • CLASS torchvision.transforms.ToTensor
    Convert a PIL Image or numpy.ndarray to tensor.转换为张量
    FloatTensor of shape (C x H x W) in the range [0.0, 1.0] if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK, 1) or if the numpy.ndarray has dtype = np.uint8

发布了2 篇原创文章 · 获赞 9 · 访问量 168

猜你喜欢

转载自blog.csdn.net/qq_45171138/article/details/104463279