chainer.functions.upsampling_2d

chainer.functions.upsampling_2d(x, indexes, ksize, stride=None, pad=0, outsize=None, cover_all=True)[source]

Upsampling using pooling indices.

This function produces an upsampled image using pooling indices.

Example

>>> x = np.arange(1, 37).reshape(1, 1, 6, 6).astype(np.float32)
>>> x = chainer.Variable(x)
>>> x.array
array([[[[ 1.,  2.,  3.,  4.,  5.,  6.],
         [ 7.,  8.,  9., 10., 11., 12.],
         [13., 14., 15., 16., 17., 18.],
         [19., 20., 21., 22., 23., 24.],
         [25., 26., 27., 28., 29., 30.],
         [31., 32., 33., 34., 35., 36.]]]], dtype=float32)

This is the original x before max pooling.

>>> pooled_x, indexes = F.max_pooling_2d(
...     x, ksize=2, stride=2, return_indices=True)
>>> pooled_x.array
array([[[[ 8., 10., 12.],
         [20., 22., 24.],
         [32., 34., 36.]]]], dtype=float32)
>>> indexes
array([[[[3, 3, 3],
         [3, 3, 3],
         [3, 3, 3]]]])

These are the outputs from the max pooling operation including the resulting indices that will be used to upsample pooled_x. Note that the indices all point to the largest, in the case the last, elements in each window.

>>> upsampled_x = F.upsampling_2d(
...     pooled_x, indexes, ksize=2, stride=2, outsize=x.shape[2:])
>>> upsampled_x.shape
(1, 1, 6, 6)
>>> upsampled_x.array
array([[[[ 0.,  0.,  0.,  0.,  0.,  0.],
         [ 0.,  8.,  0., 10.,  0., 12.],
         [ 0.,  0.,  0.,  0.,  0.,  0.],
         [ 0., 20.,  0., 22.,  0., 24.],
         [ 0.,  0.,  0.,  0.,  0.,  0.],
         [ 0., 32.,  0., 34.,  0., 36.]]]], dtype=float32)
Parameters
  • x (Variable) – Input variable.

  • indexes (N-dimensional array) – Index array returned from preceding call to max_pooling_2d().

  • ksize (int or pair of ints) – Size of pooling window. ksize=k and ksize=(k, k) are equivalent.

  • stride (int or pair of ints or None) – Stride of pooling applications. stride=s and stride=(s, s) are equivalent. If None is specified, then it uses same stride as the pooling window size.

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

  • outsize ((int, int)) – Expected output size (height, width).

  • cover_all (bool) – Should be set to True if all spatial locations were pooled into some output pixels during the preceding pooling operation. False otherwise. See max_pooling_2d().

Returns

Output variable.

Return type

Variable