mindspore.mint.nn.ReflectionPad2d
- class mindspore.mint.nn.ReflectionPad2d(padding)[source]
Pad the last 2 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.
- Inputs:
input (Tensor) - 3D or 4D input Tensor with shape: \((C, H_{in}, W_{in})\) or \((N, C, H_{in}, W_{in})\).
- Outputs:
Tensor, the tensor after padding.
- Raises
TypeError – If padding is not an integer of a list or tuple of 4 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, 8]]]).astype(np.float32)) >>> # x has shape (1, 3, 3) >>> padding = (1, 1, 2, 0) >>> pad2d = ms.mint.nn.ReflectionPad2d(padding) >>> # The first dimension of x remains the same. >>> # The second dimension of x: H_out = H_in + pad_up + pad_down = 3 + 1 + 1 = 5 >>> # The third dimension of x: W_out = W_in + pad_left + pad_right = 3 + 2 + 0 = 5 >>> out = pad2d(x) >>> # The shape of out is (1, 5, 5) >>> print(out) [[[7. 6. 7. 8. 7.] [4. 3. 4. 5. 4.] [1. 0. 1. 2. 1.] [4. 3. 4. 5. 4.] [7. 6. 7. 8. 7.]]]