resized_crop¶
- torchvision.transforms.functional.resized_crop(img: Tensor, top: int, left: int, height: int, width: int, size: List[int], interpolation: InterpolationMode = InterpolationMode.BILINEAR, antialias: Optional[bool] = None) Tensor[source]¶
Crop the given image and resize it to desired size. If the image is torch Tensor, it is expected to have […, H, W] shape, where … means an arbitrary number of leading dimensions
Notably used in
RandomResizedCrop.- Parameters:
img (PIL Image or Tensor) – Image to be cropped. (0,0) denotes the top left corner of the image.
top (int) – Vertical component of the top left corner of the crop box.
left (int) – Horizontal component of the top left corner of the crop box.
height (int) – Height of the crop box.
width (int) – Width of the crop box.
size (sequence or int) – Desired output size. Same semantics as
resize.interpolation (InterpolationMode) – Desired interpolation enum defined by
torchvision.transforms.InterpolationMode. Default isInterpolationMode.BILINEAR. If input is Tensor, onlyInterpolationMode.NEAREST,InterpolationMode.BILINEARandInterpolationMode.BICUBICare supported. For backward compatibility integer values (e.g.PIL.Image[.Resampling].NEAREST) are still accepted, but deprecated since 0.13 and will be removed in 0.15. Please use InterpolationMode enum.antialias (bool, optional) – antialias flag. If
imgis PIL Image, the flag is ignored and anti-alias is always used. Ifimgis Tensor, the flag is False by default and can be set to True forInterpolationMode.BILINEARandInterpolationMode.BICUBICmodes. This can help making the output for PIL images and tensors closer.
- Returns:
Cropped image.
- Return type:
PIL Image or Tensor
Examples using
resized_crop: