Shortcuts

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.int32torch.int64 时, 以及尝试将 torch.float64 转换为 torch.int64 时。这些转换可能会导致 溢出错误,因为浮点 dtype 无法在整个整数 dtype 范围内存储连续的整数。

使用 convert_image_dtype 的示例:

将口罩重新利用为边界框

Repurposing masks into bounding boxes