ReflectionPad2D

class paddle.nn. ReflectionPad2D ( padding: Tensor | Sequence[int] | int, data_format: DataLayout2D = 'NCHW', name: str | None = None ) [source]

This interface is used to construct a callable object of the ReflectionPad2D class. Pads the input tensor boundaries using reflection of the input boundaries.

Parameters
  • padding (Tensor | Sequence[int] | int) – The padding size. If padding is an int, the same padding is applied to all four sides (left, right, top, bottom). If padding is a list or tuple of four ints, it is interpreted as (pad_left, pad_right, pad_top, pad_bottom). Padding width must be less than the corresponding input dimension.

  • data_format (str|None) – An string from: “NCHW”, “NHWC”. Specify the data format of the input data. Default: "NCHW"

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

Shape:
  • x(Tensor): The input tensor of reflectionpad2d operator, which is a 4-D tensor. The data type can be float32, float64.

  • output(Tensor): The output tensor of reflectionpad2d operator, which is a 4-D tensor. The data type is same as input x.

Returns

The padded tensor.

Return type

Tensor

Examples

>>> import paddle
>>> import paddle.nn as nn
>>> # from reflection_padding_layers import ReflectionPad2D

>>> input_shape = (1, 1, 2, 3)
>>> pad = [1, 0, 1, 1] # L=1, R=0, T=1, B=1
>>> data = paddle.arange(paddle.prod(paddle.to_tensor(input_shape)), dtype="float32").reshape(input_shape) + 1
>>> # data = [[[[1., 2., 3.], [4., 5., 6.]]]]
>>> my_pad = nn.ReflectionPad2D(padding=pad)
>>> result = my_pad(data)
>>> print(result)
    Tensor(shape=[1, 1, 4, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[[[5., 4., 5., 6.],
            [2., 1., 2., 3.],
            [5., 4., 5., 6.],
            [2., 1., 2., 3.]]]])