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
的示例