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