Shortcuts

转换图像数据类型

class torchvision.transforms.v2.ConvertImageDtype(dtype: dtype = torch.float32)[source]

[已弃用] 请使用 v2.ToDtype(dtype, scale=True) 代替。

将输入图像转换为给定的dtype并相应地缩放值。

警告

考虑使用 ToDtype(dtype, scale=True) 代替。参见 ToDtype

此函数不支持PIL图像。

Parameters:

dtype (torch.dpython:type) – 期望的输出数据类型

注意

当从较小的整数转换为较大的整数dtype时,最大值不会精确映射。 如果来回转换,这种不匹配没有影响。

Raises:

RuntimeError – 当尝试将 torch.float32 转换为 torch.int32torch.int64 时, 以及尝试将 torch.float64 转换为 torch.int64 时。这些转换可能会导致 溢出错误,因为浮点 dtype 无法在整个整数 dtype 范围内存储连续的整数。