convert_image_dtype¶
- torchvision.transforms.functional.convert_image_dtype(image: Tensor, dtype: dtype = torch.float32) Tensor [source]¶
将张量图像转换为给定的
dtype
并相应地缩放值。此函数不支持 PIL Image。- 参数:
image (torch.Tensor) – 要转换的图像
dtype (torch.dpython:type) – 期望的输出数据类型
- 返回:
转换后的图像
- 返回类型:
Tensor
注意
当从较小的整数
dtype
转换为较大的整数dtype
时,最大值**不会**精确映射。如果来回转换,这种不匹配没有影响。- 引发:
RuntimeError – 尝试将
torch.float32
转换为torch.int32
或torch.int64
,以及尝试将torch.float64
转换为torch.int64
时发生。这些转换可能导致溢出错误,因为浮点dtype
无法在整数dtype
的整个范围内存储连续整数。
使用
convert_image_dtype
的示例