BatchRandomResizedCrop#

class torchaug.batch_transforms.BatchRandomResizedCrop(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=InterpolationMode.BILINEAR, antialias=True, num_rand_calls=-1)[source]#

Crop a random portion of a batch of images and resize it to a given size.

The batch shape is expected to be [B, …, H, W], where … means an arbitrary number of dimensions

A crop of the original image is made: the crop has a random area (H * W) and a random aspect ratio. This crop is finally resized to the given size. This is popularly used to train the Inception networks.

Parameters:
  • size (Union[int, Sequence[int]]) –

    Expected output size of the crop, for each edge. If size is an int instead of sequence like (h, w), a square output size (size, size) is made. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).

    Note

    In torchscript mode size as single int is not supported, use a sequence of length 1: [size, ].

  • scale (Sequence[float], optional) – Specifies the lower and upper bounds for the random area of the crop, before resizing. The scale is defined with respect to the area of the original image.

    Default: (0.08, 1.0)

  • ratio (Sequence[float], optional) – lower and upper bounds for the random aspect ratio of the crop, before resizing.

    Default: (0.75, 1.3333333333333333)

  • interpolation (InterpolationMode, optional) – Desired interpolation enum defined by torchvision.transforms.InterpolationMode. Only InterpolationMode.NEAREST, InterpolationMode.NEAREST_EXACT, InterpolationMode.BILINEAR and InterpolationMode.BICUBIC are supported.

    Default: InterpolationMode.BILINEAR

  • antialias (bool, optional) – Whether to apply antialiasing. It only affects bilinear or bicubic modes and it is ignored otherwise.

    Default: True

  • num_rand_calls (int, optional) – Number of random calls performed to apply augmentations at different orders on sub-batches. If -1, B calls are performed. The maximum is 24 = 4!.

    Default: -1

forward(imgs)[source]#

Resize and crop the batch of images.

Note

Apply different scaling and cropping based on num_rand_calls.

Parameters:

imgs (Tensor) – Batch of images to be cropped and resized.

Return type:

Tensor

Returns:

Randomly cropped and resized batch of images.

single_forward(imgs)[source]#

Perform a random resized crop of same scale and shape for the batch of images.

Parameters:

img – Batch of images to be cropped and resized.

Return type:

Tensor

Returns:

Cropped and resized batch of images.