RandomResize¶
- 类 torchvision.transforms.v2.RandomResize(min_size: int, max_size: int, interpolation: Union[InterpolationMode, int] = InterpolationMode.BILINEAR, antialias: Optional[bool] = True)[源]¶
随机调整输入尺寸。
此变换可与
RandomCrop
一起用作数据增强,用于训练图像分割任务的模型。输出空间尺寸从区间
[min_size, max_size]
中随机采样。size = uniform_sample(min_size, max_size) output_width = size output_height = size
如果输入是
torch.Tensor
或TVTensor
(例如Image
,Video
,BoundingBoxes
等),它可以具有任意数量的前导批处理维度。例如,图像可以具有[..., C, H, W]
形状。边界框可以具有[..., 4]
形状。- 参数:
min_size (int) – 随机采样时的最小输出尺寸
max_size (int) – 随机采样时的最大输出尺寸
interpolation (InterpolationMode, optional) – 由
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 后端保持一致。