快捷方式

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.NEARESTInterpolationMode.NEAREST_EXACTInterpolationMode.BILINEARInterpolationMode.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 的範例

Transforms 的說明

Transforms 的說明

文件

取得 PyTorch 的完整開發人員文件

檢視文件

教學

取得初學者和進階開發人員的深入教學

檢視教學

資源

尋找開發資源並獲得問題解答

檢視資源