Shortcuts

torch.quantized_batch_norm

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

对一个4D(NCHW)量化张量应用批量归一化。

y=xE[x]Var[x]+ϵγ+βy = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
Parameters
  • 输入 (张量) – 量化张量

  • 权重 (张量) – 对应于伽马的浮点张量,大小为C

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

  • 均值 (Tensor) – 批量归一化中的浮点均值,大小为 C

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

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

  • output_scale (float) – 输出量化张量的缩放比例

  • output_zero_point (int) – 输出量化张量的零点

Returns

应用了批量标准化的量化张量。

Return type

张量

示例:

>>> 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)
张量([[[[-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]]]], 大小=(2, 2, 2, 2), dtype=torch.quint8,
   量化方案=torch.per_tensor_affine, 比例=0.2, 零点=2)