Table of Contents
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

  Performs Deformable Convolution v2, described in Deformable ConvNets v2: More Deformable, Better Results if `mask` is not `None` and Performs Deformable Convolution, described in Deformable Convolutional Networks if `mask` is `None`.

  Parameters:

    - input (Tensor[batch_size, in_channels, in_height, in_width]) – input tensor

    - offset (Tensor[batch_size, 2 * offset_groups * kernel_height * kernel_width, out_height, out_width]) – offsets to be applied for each position in the convolution kernel.

    - weight (Tensor[out_channels, in_channels // groups, kernel_height, kernel_width]) – convolution weights, split into groups of size (in_channels // groups)

    - bias (Tensor[out_channels]) – optional bias of shape (out_channels,). Default: None

    - stride (int or Tuple[int, int]) – distance between convolution centers. Default: 1

    - padding (int or Tuple[int, int]) – height/width of padding of zeroes around each image. Default: 0

    - dilation (int or Tuple[int, int]) – the spacing between kernel elements. Default: 1

    - mask (Tensor[batch_size, offset_groups * kernel_height * kernel_width, out_height, out_width]) – masks to be applied for each position in the convolution kernel. Default: None

  Returns:

    result of convolution

  Return type:

    Tensor[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])

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.