Shortcuts

conv2d

class 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)[源代码]

对由多个输入平面组成的量化2D输入进行2D卷积操作。

详情和输出形状请参见 Conv2d

Parameters
  • 输入 – 形状为 (minibatch,in_channels,iH,iW)(\text{minibatch} , \text{in\_channels} , iH , iW) 的量化输入张量

  • 权重 – 形状为 (out_channels,in_channelsgroups,kH,kW)(\text{out\_channels} , \frac{\text{in\_channels}}{\text{groups}} , kH , kW)

  • bias非量化 bias 张量,形状为 (out_channels)(\text{out\_channels})。张量类型必须为 torch.float

  • 步幅 – 卷积核的步幅。可以是单个数字或元组 (sH, sW)。默认值:1

  • 填充 – 输入两侧的隐式填充。可以是单个数字或元组 (padH, padW)。默认值:0

  • dilation – 核元素之间的间距。可以是单个数字或元组 (dH, dW)。默认值:1

  • groups – 将输入分成多个组,in_channels\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)
优云智算