torch.quantized_batch_norm

torch.quantized_batch_norm(input, weight=None, bias=None, mean, var, eps, output_scale, output_zero_point)Tensor

对4D(NCHW)量化张量进行批规范化处理。

$y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta$
参数
  • 输入 (Tensor) – 一个量化张量

  • weight (Tensor) – 大小为 C 的浮点张量,对应于 gamma

  • bias (Tensor) – 大小为 C 的浮点张量,对应于 beta

  • mean (Tensor) – 批量归一化的浮点均值,维度为 C

  • var (Tensor) – 表示方差的浮点张量,大小为 C

  • eps (float) – 分母中为了数值稳定性而添加的一个值。

  • output_scale (float) – 表示输出量化张量缩放比例的浮点数

  • output_zero_point (int) — 表示输出量化张量的零点

返回值

经过批归一化处理的量化张量。

返回类型

张量

示例:

>>> qx = torch.quantize_per_tensor(torch.rand(2, 2, 2, 2), 1.5, 3, torch.quint8)
>>> torch.quantized_batch_norm(qx, torch.ones(2), torch.zeros(2), torch.rand(2), torch.rand(2), 0.00001, 0.2, 2)
tensor([[[[-0.2000, -0.2000],
      [ 1.6000, -0.2000]],

     [[-0.4000, -0.4000],
      [-0.4000,  0.6000]]],


    [[[-0.2000, -0.2000],
      [-0.2000, -0.2000]],

     [[ 0.6000, -0.4000],
      [ 0.6000, -0.4000]]]], size=(2, 2, 2, 2), dtype=torch.quint8,
   quantization_scheme=torch.per_tensor_affine, scale=0.2, zero_point=2)
本页目录