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