mindspore.ops.deformable_conv2d

mindspore.ops.deformable_conv2d(x, weight, offsets, kernel_size, strides, padding, bias=None, dilations=(1, 1, 1, 1), groups=1, deformable_groups=1, modulated=True)[source]

Given 4D tensor inputs x, weight and offsets, compute a 2D deformable convolution. The deformable convolution operation can be expressed as follow:

Deformable Convolution v1:

y(p)=k=1Kwkx(p+pk+Δpk)

Deformable Convolution v2:

y(p)=k=1Kwkx(p+pk+Δpk)Δmk

Where Δpk and Δmk are the learnable offset and modulation scalar for the k-th location. For details, please refer to Deformable ConvNets v2: More Deformable, Better Results and Deformable Convolutional Networks.

Parameters
  • x (Tensor) – A 4D tensor of input image. With the format “NCHW”, the shape is (N,Cin,Hin,Win). Dtype: float16 or float32.

  • weight (Tensor) – A 4D tensor of learnable filters. Must have the same type as x. The shape is (Cout,Cin/groups,Hf,Wf).

  • offsets (Tensor) – A 4D tensor of x-y coordinates offset and mask. With the format “NCHW”, the shape is (batch,3deformable_groupsHfWf,Hout,Wout). Note the C dimension is stored in the order of (offset_x, offset_y, mask). Must have the same type as x.

  • kernel_size (tuple[int]) – A tuple of 2 integers. The size of kernel.

  • strides (tuple[int]) – A tuple of 4 integers. The stride of the sliding window for each dimension of input. The dimension order is interpreted according to the data format of x. The N and C dimensions must be set to 1.

  • padding (tuple[int]) – A tuple of 4 integers. The number of pixels to add to each (top, bottom, left, right) side of the input.

  • bias (Tensor, Optional) – An 1D tensor of additive biases to the filter outputs. The shape is (Cout). Defaults to None.

  • dilations (tuple[int], Optional) – A tuple of 4 integers. The dilation factor for each dimension of input. The dimension order is interpreted according to the data format of x. The N and C dimensions must be set to 1. Defaults to (1, 1, 1, 1).

  • groups (int, Optional) – An integer of type int32. The number of blocked connections from input channels to output channels. In_channels and out_channels must both be divisible by groups. Defaults to 1.

  • deformable_groups (int, Optional) – An integer of type int32. The number of deformable group partitions. In_channels must be divisible by deformable_groups. Defaults to 1.

  • modulated (bool, Optional) – Specifies version of DeformableConv2D, True means v2, False means v1, currently only supports v2. Defaults to True.

Returns

Tensor, A 4D Tensor of output feature map. With the same type as x. With the format “NCHW”, the shape is (N,Cout,Hout,Wout).

Hout=Hin+padding[0]+padding[1](Hf1)×dilations[2]1stride[0]+1Wout=Win+padding[2]+padding[3](Wf1)×dilations[3]1stride[1]+1

Supported Platforms:

Ascend GPU CPU

Raises
  • TypeError – If strides, padding, kernel_size or dilations is not a tuple with integer elements.

  • TypeError – If modulated is not a bool.

  • ValueError – If the tuple size of strides, padding, kernel_size or dilations is not expected.

  • ValueError – The N or C dimensions of ‘strides’ or dilations is not set to 1.

  • ValueError – If modulated is not set to True.

Note

  • This is an experimental interface that is subject to change or deletion.

  • For Ascend platform, the following cases are not supported:

    • Cin cannot be divisible by 8, e.g. x is (N,2,Hin,Win)

    • deformable_groups is 1, e.g. deformable_groups is 2

    • offsets value is float which does not contain a decimal part, e.g. offsets is assigned with “numpy.ones()”

    • kernel_size is less than 2, e.g. kernel_size is (1, 1)

Examples

>>> x = Tensor(np.ones((4, 3, 10, 10)), mstype.float32)
>>> kh, kw = 3, 3
>>> weight = Tensor(np.ones((5, 3, kh, kw)), mstype.float32)
>>> offsets = Tensor(np.ones((4, 3 * kh * kw, 8, 8)), mstype.float32)
>>> output = ops.deformable_conv2d(x, weight, offsets, (kh, kw), (1, 1, 1, 1), (0, 0, 0, 0))
>>> print(output.shape)
(4, 5, 8, 8)