當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python PyTorch quantized_batch_norm用法及代碼示例

本文簡要介紹python語言中 torch.quantized_batch_norm 的用法。

用法:

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

參數

  • 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) -輸出量化張量zero_point

返回

應用了批量標準化的量化張量。

返回類型

Tensor

對 4D (NCHW) 量化張量應用批量歸一化。

例子:

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

相關用法


注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.quantized_batch_norm。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。