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
It should be noted that you need to turn off
chainer.config.use_cudnn
flag when you performmax_pooling_2d()
function which will make a pooling indicies for thisupsampling_2d()
. It is becauseindexes
is never created and stored in theMaxPooling2D
object when cuDNN is used for it.>>> x = np.arange(1, 37).reshape(1, 1, 6, 6).astype('f') >>> x = chainer.Variable(x) >>> x.data 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.>>> p = F.MaxPooling2D(2, 2) >>> with chainer.using_config('use_cudnn', 'never'): ... pooled_x = p.apply((x,))[0] >>> pooled_x.data array([[[[ 8., 10., 12.], [20., 22., 24.], [32., 34., 36.]]]], dtype=float32)
This is the output of the max pooling operation.
upsampling_2d()
needsindexes
array stored in the max pooling objectp
.>>> upsampled_x = F.upsampling_2d( ... pooled_x, p.indexes, p.kh, p.sy, p.ph, x.shape[2:]) >>> upsampled_x.shape (1, 1, 6, 6) >>> upsampled_x.data 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 (ndarray or ndarray) – Index array that was used to calculate x with MaxPooling2D.
- ksize (int or (int, int)) – ksize attribute of MaxPooling2D object that is used to calculate x
- stride (int or (int, int)) – stride attribute of MaxPooling2D object that is used to calculate x
- pad (int or (int, int)) – pad attribute of MaxPooling2D object that is used to calculate x
- outsize ((int, int)) – Expected output size (height, width).
- cover_all (bool) – Whether cover_all is used in the MaxPooling2D object or not.
Returns: Output variable.
Return type: