Table of Contents
Shortcuts

# RandomResize

class torchvision.transforms.v2.RandomResize(min_size: int, max_size: int, interpolation: Union[InterpolationMode, int] = InterpolationMode.BILINEAR, antialias: Optional[Union[str, bool]] = 'warn')

  [BETA] Randomly resize the input.

  Note

  The RandomResize transform is in Beta stage, and while we do not expect disruptive breaking changes, some APIs may slightly change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753.

  This transformation can be used together with `RandomCrop` as data augmentations to train models on image segmentation task.

  Output spatial size is randomly sampled from the interval `[min_size, max_size]`:

      size = uniform_sample(min_size, max_size)
      output_width = size
      output_height = size

  If the input is a `torch.Tensor` or a `TVTensor` (e.g. `Image`, `Video`, `BoundingBoxes` etc.) it can have arbitrary number of leading batch dimensions. For example, the image can have `[..., C, H, W]` shape. A bounding box can have `[..., 4]` shape.

  Parameters:

    - min_size (int) – Minimum output size for random sampling

    - max_size (int) – Maximum output size for random sampling

    - interpolation (InterpolationMode, optional) – Desired interpolation enum defined by `torchvision.transforms.InterpolationMode`. Default is `InterpolationMode.BILINEAR`. If input is Tensor, only `InterpolationMode.NEAREST`, `InterpolationMode.NEAREST_EXACT`, `InterpolationMode.BILINEAR` and `InterpolationMode.BICUBIC` are supported. The corresponding Pillow integer constants, e.g. `PIL.Image.BILINEAR` are accepted as well.

    - antialias (bool, optional) –

      Whether to apply antialiasing. It only affects tensors with bilinear or bicubic modes and it is ignored otherwise: on PIL images, antialiasing is always applied on bilinear or bicubic modes; on other modes (for PIL images and tensors), antialiasing makes no sense and this parameter is ignored. Possible values are:

      - `True`: will apply antialiasing for bilinear or bicubic modes. Other mode aren’t affected. This is probably what you want to use.

      - `False`: will not apply antialiasing for tensors on any mode. PIL images are still antialiased on bilinear or bicubic modes, because PIL doesn’t support no antialias.

      - `None`: equivalent to `False` for tensors and `True` for PIL images. This value exists for legacy reasons and you probably don’t want to use it unless you really know what you are doing.

      The current default is `None` but will change to `True` in v0.17 for the PIL and Tensor backends to be consistent.

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.