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 [原始碼]¶
裁剪給定的圖像並將其調整為所需的大小。 如果圖像為 torch Tensor,則預期其形狀為 […, H, W],其中 … 表示任意數量的領先維度
主要用於
RandomResizedCrop
。- 參數:
img (PIL Image or Tensor) – 要裁剪的圖像。 (0,0) 表示圖像的左上角。
top (int) – 裁剪框左上角的垂直分量。
left (int) – 裁剪框左上角的水平分量。
height (int) – 裁剪框的高度。
width (int) – 裁剪框的寬度。
size (sequence or 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) –
是否應用反鋸齒。它僅影響使用雙線性或雙三次模式的 tensors,否則將被忽略:在 PIL 圖像上,反鋸齒始終應用於雙線性或雙三次模式;在其他模式下(對於 PIL 圖像和 tensors),反鋸齒沒有意義,因此會忽略此參數。可能的值為
True
(預設): 將對雙線性或雙三次模式應用反鋸齒。其他模式不受影響。這可能是您想要使用的。False
: 不會對任何模式下的 tensors 應用反鋸齒。PIL 圖像仍然會在雙線性或雙三次模式下進行反鋸齒處理,因為 PIL 不支援無反鋸齒。None
: 等同於 tensors 的False
和 PIL 圖像的True
。此值存在是為了向後相容性,除非您確實知道自己在做什麼,否則可能不想使用它。
預設值已在 v0.17 中從
None
變更為True
,以使 PIL 和 Tensor 後端保持一致。
- Returns:
裁剪後的圖像。
- Return type:
PIL Image 或 Tensor
使用
resized_crop
的範例