项目作者: pratogab

项目描述 :
Batch equivalent of PyTorch Transforms.
高级语言: Python
项目地址: git://github.com/pratogab/batch-transforms.git
创建时间: 2020-03-15T18:22:17Z
项目社区:https://github.com/pratogab/batch-transforms

开源协议:

下载


Batch Transforms

Batch equivalent of PyTorch Transforms.

  1. transform_batch = transforms.Compose([
  2. ToTensor(),
  3. Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))])
  4. for images in data_iterator:
  5. images = transform_batch(images)
  6. output = model(images)

Normalize

Applies the equivalent of torchvision.transforms.Normalize to a batch of images.

Note: This transform acts out of place by default, i.e., it does not mutate the input tensor.

__init__(mean, std, inplace=False, dtype=torch.float, device='cpu')

  • mean (sequence) – Sequence of means for each channel.
  • std (sequence) – Sequence of standard deviations for each channel.
  • inplace (bool,optional) – Bool to make this operation in-place.
  • dtype (torch.dtype,optional) – The data type of tensors to which the transform will be applied.
  • device (torch.device,optional) – The device of tensors to which the transform will be applied.

    __call__(tensor)

  • tensor (Tensor) – Tensor of size (N, C, H, W) to be normalized.

RandomCrop

Applies the equivalent of torchvision.transforms.RandomCrop to a batch of images. Images are independently transformed.

__init__(size, padding=None, device='cpu')

  • size (int) – Desired output size of the crop.
  • padding (int, optional) – Optional padding on each border of the image. Default is None, i.e no padding.
  • device (torch.device,optional) – The device of tensors to which the transform will be applied.

    __call__(tensor)

  • tensor (Tensor) – Tensor of size (N, C, H, W) to be randomly cropped.

RandomHorizontalFlip

Applies the equivalent of torchvision.transforms.RandomHorizontalFlip to a batch of images. Images are independently transformed.

Note: This transform acts out of place by default, i.e., it does not mutate the input tensor.

__init__(p=0.5, inplace=False)

  • p (float) – probability of an image being flipped.
  • inplace (bool,optional) – Bool to make this operation in-place.

    __call__(tensor)

  • tensor (Tensor) – Tensor of size (N, C, H, W) to be randomly flipped.

ToTensor

Applies the equivalent of torchvision.transforms.ToTensor to a batch of images.

__init__()

__call__(tensor)

  • tensor (Tensor) – Tensor of size (N, C, H, W) to be tensorized.