ZeroPad2D¶
- class paddle.nn. ZeroPad2D ( padding, data_format='NCHW', name=None ) [source]
- 
         This interface is used to construct a callable object of the ZeroPad2Dclass. Pads the input tensor boundaries with zero.- 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). 
- data_format (str) – An string from: “NCHW”, “NHWC”. Specify the data format of the input data. Default is “NCHW” 
- 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. 
 
 - Shape:
- 
           - x(Tensor): The input tensor of zeropad2d operator, which is a 4-D tensor. The data type can be float32, float64. 
- output(Tensor): The output tensor of zeropad2d operator, which is a 4-D tensor. The data type is same as input x. 
 
 Examples Examples are as follows. import paddle import paddle.nn as nn import numpy as np input_shape = (1, 1, 2, 3) pad = [1, 0, 1, 2] data = paddle.arange(np.prod(input_shape), dtype="float32").reshape(input_shape) + 1 my_pad = nn.ZeroPad2D(padding=pad) 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. 
 
