convert_image_dtype¶
- torchvision.transforms.functional.convert_image_dtype(image: Tensor, dtype: dtype = torch.float32) Tensor [source]¶
將張量圖像轉換為給定的
dtype
並相應地縮放值。此函數不支援 PIL 圖像。- 參數:
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
的範例