BilinearInitializer

class paddle.fluid.initializer.BilinearInitializer[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. The usage is:

Examples

import paddle.fluid as fluid
factor = 2
C = 2
B = 8
H = W = 32
w_attr = fluid.param_attr.ParamAttr(
    learning_rate=0.,
    regularizer=fluid.regularizer.L2Decay(0.),
    initializer=fluid.initializer.Bilinear())
x = fluid.data(name="data", shape=[B, 3, H, W],
                      dtype="float32")
conv_up = fluid.layers.conv2d_transpose(
    input=x,
    num_filters=C,
    output_size=None,
    filter_size=2 * factor - factor % 2,
    padding=int(math.ceil((factor - 1) / 2.)),
    stride=factor,
    groups=C,
    param_attr=w_attr,
    bias_attr=False)

Where, num_filters=C and groups=C means this is channel-wise transposed convolution. The filter shape will be (C, 1, K, K) where K is filer_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.