ConvertImageDtype¶
- class torchvision.transforms.ConvertImageDtype(dtype: dtype)[來源]¶
將張量圖像轉換為給定的
dtype
並相應地縮放值。此函式不支援 PIL Image。
- 參數:
dtype (torch.dpython:type) – 輸出所需的資料類型
注意
當從較小的整數
dtype
轉換為較大的整數dtype
時,最大值不會精確對應。如果來回轉換,這種不匹配沒有影響。- 引發:
RuntimeError – 當嘗試將
torch.float32
轉換為torch.int32
或torch.int64
,以及嘗試將torch.float64
轉換為torch.int64
時。這些轉換可能會導致溢位錯誤,因為浮點dtype
無法在整數dtype
的整個範圍內儲存連續的整數。