• 文档 >
  • torch >
  • torch.quantize_per_channel
快捷键

torch.quantize_per_channel

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

将浮点张量转换为具有给定缩放比例和零点的按通道量化的张量。

参数:
  • 输入(张量)- 要量化的浮点张量

  • 尺度(张量)- 使用尺度的浮点 1D 张量,大小应与 input.size(axis) 匹配

  • 零点(整数)- 使用偏移的整数 1D 张量,大小应与 input.size(axis) 匹配

  • 轴(整数)- 应用通道量化维度的维度

  • dtype ( torch.dtype ) – 返回张量的期望数据类型。必须是以下量化数据类型之一: torch.quint8torch.qint8torch.qint32

返回值:

一个新量化的张量

返回类型:

张量

示例:

>>> 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 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源