torch.fake_quantize_per_channel_affine#
- torch.fake_quantize_per_channel_affine(input, scale, zero_point, axis, quant_min, quant_max) Tensor#
返回一個新張量,其中
input中的資料根據scale、zero_point、quant_min和quant_max,並沿著由axis指定的通道進行每通道仿射偽量化。- 引數
- 返回
一個新偽量化的每通道
torch.float32張量- 返回型別
示例
>>> x = torch.randn(2, 2, 2) >>> x tensor([[[-0.2525, -0.0466], [ 0.3491, -0.2168]], [[-0.5906, 1.6258], [ 0.6444, -0.0542]]]) >>> scales = (torch.randn(2) + 1) * 0.05 >>> scales tensor([0.0475, 0.0486]) >>> zero_points = torch.zeros(2).to(torch.int32) >>> zero_points tensor([0, 0]) >>> torch.fake_quantize_per_channel_affine(x, scales, zero_points, 1, 0, 255) tensor([[[0.0000, 0.0000], [0.3405, 0.0000]], [[0.0000, 1.6134], [0.6323, 0.0000]]])