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 或 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, 可选) –
是否应用抗锯齿。它仅影响双线性或双三次模式的张量,否则将被忽略:在 PIL 图像上,抗锯齿始终在双线性或双三次模式下应用;在其他模式下(PIL 图像和张量),抗锯齿无意义,此参数将被忽略。可能的值为
True
(默认):将对双线性或双三次模式应用抗锯齿。其他模式不受影响。这可能是您想要使用的。False
:将不对任何模式下的张量应用抗锯齿。PIL 图像在双线性或双三次模式下仍然进行抗锯齿处理,因为 PIL 不支持无抗锯齿。None
:对于张量相当于False
,对于 PIL 图像相当于True
。此值存在是为了向后兼容,除非您确实知道自己在做什么,否则可能不希望使用它。
默认值在 v0.17 中从
None
更改为True
,以使 PIL 和 Tensor 后端保持一致。
- 返回:
裁剪后的图像。
- 返回类型:
PIL 图像或张量
使用
resized_crop
的示例