UpsamplingBilinear2D

class paddle.nn. UpsamplingBilinear2D ( size=None, scale_factor=None, data_format='NCHW', name=None ) [source]

This op upsamples a batch of images, using bilinear’ pixel values. The input must be a 4-D Tensor of the shape (num_batches, channels, in_h, in_w), where in_w is width of the input tensor, in_h is the height of the input tensor. And the upsampling only applies on the two dimensions(height and width). Bilinear interpolation is an extension of linear interpolation for interpolating functions of two variables (e.g. H-direction and W-direction in this op) on a rectilinear 2D grid. The key idea is to perform linear interpolation first in one direction, and then again in the other direction.

For details of bilinear interpolation, please refer to Wikipedia: https://en.wikipedia.org/wiki/Bilinear_interpolation.

Parameters
  • x (Tensor) – 4-D Tensor, its data type is float32, float64, or uint8, its data format is specified by data_format.

  • size (int|list|tuple|Tensor|None) – Output shape of image resize layer, the shape is (out_h, out_w) when input is a 4-D Tensor. Default: None. If an int value, the out_h and out_w will be set as the number. If a list/tuple, each element can be an integer or a Tensor of shape: [1]. If a Tensor , its dimensions size should be a 1.

  • scale_factor (float|int|list|tuple|Tensor|None) – The multiplier for the input height or width. At least one of size or scale_factor must be set. And size has a higher priority than scale_factor. Has to match input size if it is either a list or a tuple or a Tensor. Default: None.

  • data_format (str, optional) – Specify the data format of the input, and the data format of the output will be consistent with that of the input. An optional string from:NCW, NWC, “NCHW”, “NHWC”, “NCDHW”, “NDHWC”. The default is “NCHW”. When it is “NCHW”, the data is stored in the order of: [batch_size, input_channels, input_height, input_width]. When it is “NCHW”, the data is stored in the order of: [batch_size, input_channels, input_depth, input_height, input_width].

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name

Returns

A 4-D Tensor of the shape (num_batches, channels, out_h, out_w) or (num_batches, out_h, out_w, channels),

Examples

>>> import paddle
>>> import paddle.nn as nn

>>> input_data = paddle.rand(shape=(2, 3, 6, 10)).astype("float32")
>>> upsample_out  = paddle.nn.UpsamplingBilinear2D(size=[12, 12])
>>> input = paddle.to_tensor(input_data)
>>> output = upsample_out(x=input)
>>> print(output.shape)
[2, 3, 12, 12]
forward ( x )

forward

Defines the computation performed at every call. Should be overridden by all subclasses.

Parameters
  • *inputs (tuple) – unpacked tuple arguments

  • **kwargs (dict) – unpacked dict arguments

extra_repr ( )

extra_repr

Extra representation of this layer, you can have custom implementation of your own layer.