當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch quantize_per_channel用法及代碼示例

本文簡要介紹python語言中 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.org大神的英文原創作品 torch.quantize_per_channel。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。