快捷鍵

torch.quantize_per_channel

torch.quantize_per_channel(input, scales, zero_points, axis, dtype) Tensor

將浮點張量轉換為具有給定縮放和零點的每個通道量化張量。

參數
  • input (Tensor) – 要量化的浮點張量

  • scales (Tensor) – 要使用的縮放比例的浮點 1D 張量,大小應符合 input.size(axis)

  • zero_points (int) – 要使用的偏移量的整數 1D 張量,大小應符合 input.size(axis)

  • axis (int) – 在其上應用每個通道量化的維度

  • dtype (torch.dtype) – 返回張量的期望資料類型。必須是量化資料類型之一:torch.quint8torch.qint8torch.qint32

返回值

一個新量化的張量

返回類型

Tensor

範例

>>> x = torch.tensor([[-1.0, 0.0], [1.0, 2.0]])
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8)
tensor([[-1.,  0.],
        [ 1.,  2.]], size=(2, 2), dtype=torch.quint8,
       quantization_scheme=torch.per_channel_affine,
       scale=tensor([0.1000, 0.0100], dtype=torch.float64),
       zero_point=tensor([10,  0]), axis=0)
>>> torch.quantize_per_channel(x, torch.tensor([0.1, 0.01]), torch.tensor([10, 0]), 0, torch.quint8).int_repr()
tensor([[  0,  10],
        [100, 200]], dtype=torch.uint8)

文件

存取 PyTorch 的完整開發者文件

檢視文件

教學

取得針對初學者和進階開發者的深入教學

檢視教學

資源

尋找開發資源並取得您問題的解答

檢視資源