Pad3D

class paddle.nn. Pad3D ( padding, mode='constant', value=0.0, data_format='NCDHW', name=None ) [source]

This interface is used to construct a callable object of the Pad3D class. Pad tensor according to ‘pad’, ‘mode’ and ‘value’. If mode is ‘reflect’, pad[0] and pad[1] must be no greater than width-1. The height and depth dimension has the same condition.

Parameters
  • padding (Tensor | List[int] | int) – The padding size with data type int. If is int, use the same padding in all dimensions. Else [len(padding)/2] dimensions of input will be padded. The pad has the form (pad_left, pad_right, pad_top, pad_bottom, pad_front, pad_back).

  • mode (str) – Four modes: ‘constant’ (default), ‘reflect’, ‘replicate’, ‘circular’. When in ‘constant’ mode, this op uses a constant value to pad the input tensor. When in ‘reflect’ mode, uses reflection of the input boundaries to pad the input tensor. When in ‘replicate’ mode, uses input boundaries to pad the input tensor. When in ‘circular’ mode, uses circular input to pad the input tensor. Default is ‘constant’.

  • value (float32) – The value to fill the padded areas. Default is 0.0

  • data_format (str) – An string from: “NCDHW”, “NDHWC”. Specify the data format of the input data. Default is “NCDHW”

  • 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

None

Examples

x = [[[[[1., 2., 3.],
        [4., 5., 6.]]]]]
padding = [1, 2, 0, 0, 0, 0]
mode = "constant"
value = 0.0
Out = [[[[[0. 1. 2. 3. 0. 0.]
          [0. 4. 5. 6. 0. 0.]]]]]
Code Examples:
import paddle
import paddle.nn as nn
import numpy as np
input_shape = (1, 1, 1, 2, 3)
pad = [1, 0, 1, 2, 0, 0]
mode = "constant"
data = paddle.arange(np.prod(input_shape), dtype="float32").reshape(input_shape) + 1
my_pad = nn.Pad3D(padding=pad, mode=mode)
result = my_pad(data)
print(result)
# [[[[[0. 0. 0. 0.]
#     [0. 1. 2. 3.]
#     [0. 4. 5. 6.]
#     [0. 0. 0. 0.]
#     [0. 0. 0. 0.]]]]]
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.