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] = True) Tensor[source]¶
裁剪給定影像並將其縮放到所需尺寸。如果影像是 torch Tensor,則其形狀應為 […, H, W],其中 … 表示任意數量的前導維度。
主要用於
RandomResizedCrop。- 引數:
img (PIL Image 或 Tensor) – 要裁剪的影像。(0,0) 表示影像的左上角。
top (int) – 裁剪框左上角的垂直分量。
left (int) – 裁剪框左上角的水平分量。
height (int) – 裁剪框的高度。
width (int) – 裁剪框的寬度。
size (sequence 或 int) – 所需的輸出尺寸。語義與
resize相同。interpolation (InterpolationMode) – 由
torchvision.transforms.InterpolationMode定義的所需插值列舉。預設為InterpolationMode.BILINEAR。如果輸入是 Tensor,則僅支援InterpolationMode.NEAREST、InterpolationMode.NEAREST_EXACT、InterpolationMode.BILINEAR和InterpolationMode.BICUBIC。同樣接受相應的 Pillow 整型常量,例如PIL.Image.BILINEAR。antialias (bool, optional) –
是否應用抗鋸齒。它隻影響採用雙線性或雙三次模式的 tensor,在其他情況下會被忽略:對於 PIL 影像,在雙線性或雙三次模式下始終應用抗鋸齒;對於其他模式(PIL 影像和 tensor),抗鋸齒沒有意義,此引數將被忽略。可能的值有:
True(預設):將對抗鋸齒用於雙線性或雙三次模式。其他模式不受影響。這可能是您想要使用的。False:不會對任何模式下的 tensor 應用抗鋸齒。PIL 影像在雙線性或雙三次模式下仍然會進行抗鋸齒,因為 PIL 不支援不進行抗鋸齒。None:對於 tensor 等同於False,對於 PIL 影像等同於True。此值出於歷史原因而存在,除非您非常清楚自己在做什麼,否則可能不應使用它。
為了使 PIL 和 Tensor 後端保持一致,預設值在 v0.17 版本中從
None更改為True。
- 返回值:
裁剪後的影像。
- 返回型別:
PIL Image 或 Tensor
使用
resized_crop的示例