評價此頁

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=xE[x]Var[x]+ϵγ+βy = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
引數
  • input (Tensor) – 量化張量

  • weight (Tensor) – 對應 gamma 的浮點張量,大小為 C

  • bias (Tensor) – 對應 beta 的浮點張量,大小為 C

  • 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)