ConvertImageDtype¶
- class torchvision.transforms.v2.ConvertImageDtype(dtype: dtype = torch.float32)[源代码]¶
[已弃用] 请改用
v2.ToDtype(dtype, scale=True)
。将输入图像转换为给定的
dtype
并相应地缩放值。警告
考虑改用
ToDtype(dtype, scale=True)
。请参阅ToDtype
。此函数不支持 PIL Image。
- 参数:
dtype (torch.dpython:type) – 输出的期望数据类型
注意
当从较小的整数
dtype
转换为较大的整数dtype
时,最大值不会完全映射。如果来回转换,这种不匹配没有影响。- 引发:
RuntimeError – 当尝试将
torch.float32
转换为torch.int32
或torch.int64
,以及尝试将torch.float64
转换为torch.int64
时。这些转换可能会导致溢出错误,因为浮点dtype
无法在整数dtype
的整个范围内存储连续的整数。