mindspore.mint.nn.ConstantPad2d
- class mindspore.mint.nn.ConstantPad2d(padding, value)[source]
Pad the last 2-D dimensions of input tensor using padding and value.
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
- Inputs:
input (Tensor) - The input tensor with shape \((N, *)\), where \(*\) means any number of additional dimensions.
- Outputs:
Tensor, the tensor after padding.
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> x = mindspore.mint.ones((1, 2, 3, 4), dtype=mindspore.float32) >>> padding = (1, 1, 0, 1) >>> value = 0.5 >>> pad2d = mindspore.mint.nn.ConstantPad2d(padding, value) >>> out = pad2d(x) >>> print(out) [[[[0.5 1. 1. 1. 1. 0.5] [0.5 1. 1. 1. 1. 0.5] [0.5 1. 1. 1. 1. 0.5] [0.5 0.5 0.5 0.5 0.5 0.5]] [[0.5 1. 1. 1. 1. 0.5] [0.5 1. 1. 1. 1. 0.5] [0.5 1. 1. 1. 1. 0.5] [0.5 0.5 0.5 0.5 0.5 0.5]]]] >>> print(out.shape) (1, 2, 4, 6)