mindspore.mint.nn.ReflectionPad1d

class mindspore.mint.nn.ReflectionPad1d(padding)[source]

Pad the last dimension of input tensor using the reflection of the input boundary.

For more information, please refer to mindspore.mint.nn.functional.pad().

Warning

This is an experimental API that is subject to change or deletion.

Parameters

padding (Union[int, tuple, list]) – Specifies padding size.

Inputs:
  • input (Tensor) - 2D or 3D input Tensor with shape: \((C, W_{in})\) or \((N, C, W_{in})\).

Outputs:

Tensor, the tensor after padding.

Raises
  • TypeError – If padding is not an integer of a list or tuple of 2 integers.

  • TypeError – If input is not Tensor.

  • ValueError – If padding contains negative value.

  • ValueError – If padding is a tuple or list, and the length does not match the tensor dimension.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> x = ms.Tensor(np.array([[[0, 1, 2, 3], [4, 5, 6, 7]]]).astype(np.float32))
>>> # x has shape (1, 2, 4)
>>> padding = (3, 1)
>>> # The first and the second dimension of x remain the same.
>>> # The third dimension of x: W_out = W_in + pad_left + pad_right = 4 + 3 + 1 = 8
>>> pad1d = ms.mint.nn.ReflectionPad1d(padding)
>>> out = pad1d(x)
>>> # The shape of out is (1, 2, 8)
>>> print(out)
[[[3. 2. 1. 0. 1. 2. 3. 2.]
  [7. 6. 5. 4. 5. 6. 7. 6.]]]