Shortcuts

deform_conv2d

torchvision.ops.deform_conv2d(input: Tensor, offset: Tensor, weight: Tensor, bias: Optional[Tensor] = None, stride: Tuple[int, int] = (1, 1), padding: Tuple[int, int] = (0, 0), dilation: Tuple[int, int] = (1, 1), mask: Optional[Tensor] = None) Tensor[source]

执行可变形卷积v2,描述在 Deformable ConvNets v2: More Deformable, Better Results 如果 mask 不是 None 并且 执行可变形卷积,描述在 Deformable Convolutional Networks 如果 maskNone

Parameters:
  • 输入 (张量[批量大小, 输入通道数, 输入高度, 输入宽度]) – 输入张量

  • offset (Tensor[batch_size, 2 * offset_groups * kernel_height * kernel_width, out_height, out_width]) – 在卷积核的每个位置上应用的偏移量。

  • weight (Tensor[out_channels, in_channels // groups, kernel_height, kernel_width]) – 卷积权重, 分成大小为 (in_channels // groups) 的组

  • bias (Tensor[out_channels]) – 可选的偏置,形状为 (out_channels,)。默认值:None

  • stride (intTuple[int, int]) – 卷积中心之间的距离。默认值:1

  • padding (intTuple[int, int]) – 每张图像周围零填充的高度/宽度。默认值:0

  • dilation (intTuple[int, int]) – 内核元素之间的间距。默认值:1

  • mask (Tensor[batch_size, offset_groups * kernel_height * kernel_width, out_height, out_width]) – 用于卷积核中每个位置的掩码。默认值:None

Returns:

卷积的结果

Return type:

张量[batch_sz, out_channels, out_h, out_w]

Examples::
>>> input = torch.rand(4, 3, 10, 10)
>>> kh, kw = 3, 3
>>> weight = torch.rand(5, 3, kh, kw)
>>> # offset and mask should have the same spatial size as the output
>>> # of the convolution. In this case, for an input of 10, stride of 1
>>> # and kernel size of 3, without padding, the output size is 8
>>> offset = torch.rand(4, 2 * kh * kw, 8, 8)
>>> mask = torch.rand(4, kh * kw, 8, 8)
>>> out = deform_conv2d(input, offset, weight, mask=mask)
>>> print(out.shape)
>>> # returns
>>>  torch.Size([4, 5, 8, 8])