GroupNorm¶
- class paddle.nn. GroupNorm ( num_groups, num_channels, epsilon=1e-05, weight_attr=None, bias_attr=None, data_format='NCHW', name=None ) [source]
-
This interface is used to construct a callable object of the
GroupNorm
class. For more details, refer to code examples. It implements the function of the Group Normalization Layer. Refer to Group Normalization .- Parameters
-
num_groups (int) – The number of groups that divided from channels.
num_channels (int) – The number of channels of input.
epsilon (float, optional) – The small value added to the variance to prevent division by zero. Default: 1e-05.
weight_attr (ParamAttr|bool, optional) – The parameter attribute for the learnable scale \(g\). If it is set to False, no scale will be added to the output units. If it is set to None, the scale is initialized one. Default: None.
bias_attr (ParamAttr|bool, optional) – The parameter attribute for the learnable bias \(b\). If it is set to False, no bias will be added to the output units. If it is set to None, the bias is initialized zero. Default: None.
data_format (str, optional) – Specify the input data format. Support “NCL”, “NCHW”, “NCDHW”, “NLC”, “NHWC” or “NDHWC”. Default: “NCHW”.
name (str, optional) – Name for the GroupNorm, default is None. For more information, please refer to Name..
- Shape:
-
x: Tensor with shape: attr:(batch, num_features, *).
output: The same shape as input x.
- Returns
-
None
Examples
>>> import paddle >>> paddle.seed(100) >>> x = paddle.arange(48, dtype="float32").reshape((2, 6, 2, 2)) >>> group_norm = paddle.nn.GroupNorm(num_channels=6, num_groups=6) >>> group_norm_out = group_norm(x) >>> print(group_norm_out) Tensor(shape=[2, 6, 2, 2], dtype=float32, place=Place(cpu), stop_gradient=False, [[[[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]]], [[[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]], [[-1.34163547, -0.44721183], [ 0.44721183, 1.34163547]]]])
-
forward
(
input
)
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.