Bilinear

class paddle.nn.initializer. Bilinear [source]

This initializer can be used in transposed convolution operator to act as upsampling. Users can upsample a feature map with shape of (B, C, H, W) by any integer factor.

Returns

Bilinear initializer instance objects.

Examples

>>> import math

>>> import paddle
>>> import paddle.nn as nn
>>> from paddle.regularizer import L2Decay

>>> factor = 2
>>> C = 2
>>> B = 8
>>> H = W = 32
>>> w_attr = paddle.ParamAttr(learning_rate=0.,
...                           regularizer=L2Decay(0.),
...                           initializer=nn.initializer.Bilinear())
>>> data = paddle.rand([B, 3, H, W], dtype='float32')
>>> conv_up = nn.Conv2DTranspose(3,
...                              out_channels=C,
...                              kernel_size=2 * factor - factor % 2,
...                              padding=int(
...                                  math.ceil((factor - 1) / 2.)),
...                              stride=factor,
...                              weight_attr=w_attr,
...                              bias_attr=False)
>>> x = conv_up(data)

Where, out_channels=C and groups=C means this is channel-wise transposed convolution. The filter shape will be (C, 1, K, K) where K is kernel_size, This initializer will set a (K, K) interpolation kernel for every channel of the filter identically. The resulting shape of the output feature map will be (B, C, factor * H, factor * W). Note that the learning rate and the weight decay are set to 0 in order to keep coefficient values of bilinear interpolation unchanged during training.

forward ( var, block=None )

forward

Initialize the input tensor with Bilinear initialization.

Parameters
  • var (Tensor) – Tensor that needs to be initialized.

  • block (Block, optional) – The block in which initialization ops should be added. Used in static graph only, default None.

Returns

The initialization op