chainer.functions.deformable_convolution_2d_sampler

chainer.functions.deformable_convolution_2d_sampler(x, offset, W, b=None, stride=1, pad=0)[source]

Two-dimensional deformable convolution function using computed offset.

This is an implementation of two-dimensional deformable convolution from Deformable Convolutional Networks.

It takes four variables: the input image x, the offset image offset, the filter weight W, and the bias vector b.

Notation: here is the notation for the dimensionalities.

  • \(n\) is the batch size.

  • \(c_I\) and \(c_O\) are the number of the input and output, respectively.

  • \(h\) and \(w\) are the height and width of the input image, respectively.

  • \(k_H\) and \(k_W\) are the height and width of the filters, respectively.

  • \(s_Y\) and \(s_X\) are the strides of the filter.

  • \(p_H\) and \(p_W\) are the spatial padding sizes.

The output size \((h_O, w_O)\) is determined by the following equations:

\[\begin{split}h_O &= (h + 2p_H - k_H) / s_Y + 1,\\ w_O &= (w + 2p_W - k_W) / s_X + 1.\end{split}\]
Parameters
  • x (Variable or N-dimensional array) – Input variable of shape \((n, c_I, h, w)\).

  • offset (Variable or N-dimensional array) – Offset variable of shape \((n, 2 \cdot k_H \cdot k_W, h_O, w_O)\). The first \(k_H \cdot k_W\) index of the second axis corresponds to the offsets in the horizontal direction. The last \(k_H \cdot k_W\) index of the second axis corresponds to the offsets in the vertical direction.

  • W (Variable or N-dimensional array) – Weight variable of shape \((c_O, c_I, k_H, k_W)\).

  • b (Variable or N-dimensional array) – Bias variable of length \(c_O\) (optional).

  • stride (int or pair of ints) – Stride of filter applications. stride=s and stride=(s, s) are equivalent.

  • pad (int or pair of ints) – Spatial padding width for input arrays. pad=p and pad=(p, p) are equivalent.

Returns

Output variable.

Return type

Variable

Deformable convolution adds 2D offsets to the regular grid sampling locations in the standard convolution. It enables free form deformation of the sampling grid.

See Jifeng Dai, Haozhi Qi, Yuwen Xiong, Yi Li, Guodong Zhang, Han Hu, Yichen Wei. Deformable Convolutional Networks

If the bias vector is given, then it is added to all spatial locations of the output of convolution.

Example

>>> x = np.random.uniform(0, 1, (2, 3, 4, 7)).astype(np.float32)
>>> offset = np.random.uniform(
...     0, 1, (2, 2 * 3 * 3, 2, 5)).astype(np.float32)
>>> W = np.random.uniform(0, 1, (4, 3, 3, 3)).astype(np.float32)
>>> b = np.random.uniform(0, 1, (4,)).astype(np.float32)
>>> y = F.deformable_convolution_2d_sampler(x, offset, W, b)
>>> y.shape
(2, 4, 2, 5)