resized_crop¶
-
torchvision.transforms.functional.
resized_crop
(img: torch.Tensor, top: int, left: int, height: int, width: int, size: List[int], interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.BILINEAR: 'bilinear'>) → torch.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.BILINEAR
andInterpolationMode.BICUBIC
are 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.
- Returns
Cropped image.
- Return type
PIL Image or Tensor
Examples using
resized_crop
:Illustration of transforms