r""" Compute 2-D deformable convolution on 4-D input. Given input image x, output feature map y, the deformable convolution operation can be expressed as follow: Deformable Convolution v2: .. math:: y(p) = \sum_{k=1}^{K}{w_k * x(p + p_k + \Delta p_k) * \Delta m_k} De
(
x: Tensor,
offset: Tensor,
weight: Tensor,
bias: Tensor | None = None,
stride: Size2 = 1,
padding: Size2 = 0,
dilation: Size2 = 1,
deformable_groups: int = 1,
groups: int = 1,
mask: Tensor | None = None,
name: str | None = None,
)
| 768 | |
| 769 | |
| 770 | def deform_conv2d( |
| 771 | x: Tensor, |
| 772 | offset: Tensor, |
| 773 | weight: Tensor, |
| 774 | bias: Tensor | None = None, |
| 775 | stride: Size2 = 1, |
| 776 | padding: Size2 = 0, |
| 777 | dilation: Size2 = 1, |
| 778 | deformable_groups: int = 1, |
| 779 | groups: int = 1, |
| 780 | mask: Tensor | None = None, |
| 781 | name: str | None = None, |
| 782 | ) -> Tensor: |
| 783 | r""" |
| 784 | Compute 2-D deformable convolution on 4-D input. |
| 785 | Given input image x, output feature map y, the deformable convolution operation can be expressed as follow: |
| 786 | |
| 787 | |
| 788 | Deformable Convolution v2: |
| 789 | |
| 790 | .. math:: |
| 791 | |
| 792 | y(p) = \sum_{k=1}^{K}{w_k * x(p + p_k + \Delta p_k) * \Delta m_k} |
| 793 | |
| 794 | Deformable Convolution v1: |
| 795 | |
| 796 | .. math:: |
| 797 | |
| 798 | y(p) = \sum_{k=1}^{K}{w_k * x(p + p_k + \Delta p_k)} |
| 799 | |
| 800 | Where :math:`\Delta p_k` and :math:`\Delta m_k` are the learnable offset and modulation scalar for the k-th location, |
| 801 | Which :math:`\Delta m_k` is one in deformable convolution v1. Please refer to `Deformable ConvNets v2: More Deformable, Better Results |
| 802 | <https://arxiv.org/abs/1811.11168v2>`_ and `Deformable Convolutional Networks <https://arxiv.org/abs/1703.06211>`_. |
| 803 | |
| 804 | Example: |
| 805 | - Input: |
| 806 | |
| 807 | x shape: :math:`(N, C_{in}, H_{in}, W_{in})` |
| 808 | |
| 809 | weight shape: :math:`(C_{out}, C_{in}, H_f, W_f)` |
| 810 | |
| 811 | offset shape: :math:`(N, 2 * H_f * W_f, H_{out}, W_{out})` |
| 812 | |
| 813 | mask shape: :math:`(N, H_f * W_f, H_{out}, W_{out})` |
| 814 | |
| 815 | - Output: |
| 816 | |
| 817 | Output shape: :math:`(N, C_{out}, H_{out}, W_{out})` |
| 818 | |
| 819 | Where |
| 820 | |
| 821 | .. math:: |
| 822 | |
| 823 | H_{out}&= \frac{(H_{in} + 2 * paddings[0] - (dilations[0] * (H_f - 1) + 1))}{strides[0]} + 1 \\ |
| 824 | W_{out}&= \frac{(W_{in} + 2 * paddings[1] - (dilations[1] * (W_f - 1) + 1))}{strides[1]} + 1 |
| 825 | |
| 826 | Args: |
| 827 | x (Tensor): The input image with [N, C, H, W] format. A Tensor with type |