当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。