conv2d
- 类 torch.ao.nn.quantized.functional.conv2d(input, weight, bias, stride=1, padding=0, dilation=1, groups=1, padding_mode='zeros', scale=1.0, zero_point=0, dtype=torch.quint8)[源代码]
-
对该二维输入进行二维卷积运算,该输入由多个输入平面组成并已量化。
详细信息和输出形状请参见
Conv2d
。- 参数
-
-
input - 量化输入张量,其形状为$(\text{minibatch} , \text{in\_channels} , iH , iW)$
-
weight – 量化滤波器,其形状为 $(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kH , kW)$
-
bias – 非量化偏置张量,形状为$(\text{out\_channels})$。其类型必须是torch.float。
-
stride — 卷积核的步幅。可以是单个数值或元组 (sH, sW)。默认值为 1。
-
padding – 输入两边的隐含填充量。可以是单个数值或元组形式的(padH, padW)。默认值为0。
-
dilation – 卷积核元素之间的距离。可以是单个数值或元组(dH, dW)。默认值为1。
-
groups — 将输入分为多个组,其中 $\text{in\_channels}$ 应该能够被组的数量整除。默认值:1
-
padding_mode - 填充模式,当前仅支持量化卷积的 "zeros" 模式。默认值: "zeros"
-
scale - 输出的量化比例因子。默认值:1.0
-
zero_point - 输出量化的零点值。默认值:0
-
dtype – 用于量化的数据类型。默认值:
torch.quint8
-
示例:
>>> from torch.ao.nn.quantized import functional as qF >>> filters = torch.randn(8, 4, 3, 3, dtype=torch.float) >>> inputs = torch.randn(1, 4, 5, 5, dtype=torch.float) >>> bias = torch.randn(8, dtype=torch.float) >>> >>> scale, zero_point = 1.0, 0 >>> dtype_inputs = torch.quint8 >>> dtype_filters = torch.qint8 >>> >>> q_filters = torch.quantize_per_tensor(filters, scale, zero_point, dtype_filters) >>> q_inputs = torch.quantize_per_tensor(inputs, scale, zero_point, dtype_inputs) >>> qF.conv2d(q_inputs, q_filters, bias, padding=1, scale=scale, zero_point=zero_point)