mindspore.mint.nn.ReplicationPad2d
- class mindspore.mint.nn.ReplicationPad2d(padding)[source]
Pad the last 2 dimension of input tensor using the replication 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 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 >>> pad2d = ms.mint.nn.ReplicationPad2d(2) >>> input = ms.Tensor(np.arange(0, 9).reshape(1, 1, 3, 3), ms.float32) >>> print(input) [[[[0. 1. 2.] [3. 4. 5.] [6. 7. 8.]]]] >>> out = pad2d(input) >>> print(out) [[[[0. 0. 0. 1. 2. 2. 2.] [0. 0. 0. 1. 2. 2. 2.] [0. 0. 0. 1. 2. 2. 2.] [3. 3. 3. 4. 5. 5. 5.] [6. 6. 6. 7. 8. 8. 8.] [6. 6. 6. 7. 8. 8. 8.] [6. 6. 6. 7. 8. 8. 8.]]]] >>> pad2d = ms.mint.nn.ReplicationPad2d((1, 1, 2, 0)) >>> out = pad2d(input) >>> print(out) [[[[0. 0. 1. 2. 2.] [0. 0. 1. 2. 2.] [0. 0. 1. 2. 2.] [3. 3. 4. 5. 5.] [6. 6. 7. 8. 8.]]]]