GroupNorm
- class paddle.nn. GroupNorm ( num_groups: int, num_channels: int, epsilon: float = 1e-05, *, affine: bool = True, device: PlaceLike | None = None, dtype: DTypeLike | None = None, weight_attr: bool | ParamAttr | None = None, bias_attr: bool | ParamAttr | None = None, data_format: DataLayout1D | DataLayout2D | DataLayout3D = 'NCHW', name: str | None = None ) [source]
-
This interface is used to construct a callable object of the
GroupNormclass. 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. alias:
eps.affine (bool, optional) – Whether this module has learnable affine parameters (weight and bias). If set to
False, no learnable parameters will be created, regardless of the settings of weight_attr and bias_attr. Defaults to True. Note: This argument must be passed as a keyword argument.device (PlaceLike, optional) – Device where the computation takes place. Default: None. Note: This argument must be passed as a keyword argument.
dtype (DTypeLike, optional) – Data type of the weights and bias. Default: None. Note: This argument must be passed as a keyword argument.
weight_attr (ParamAttr|bool|None, optional) –
The parameter attribute for the learnable scale \(g\). This setting only takes effect when affine is
True. - If set toFalse, no scale parameter will be created. - If set toTrueor a ParamAttr object, a learnable scale parameter will be created.When set to
True, it is equivalent toParamAttr()with default initialization.If set to
None, a learnable scale parameter will be created and initialized to one.
Default: None. Note: This argument must be passed as a keyword argument.
bias_attr (ParamAttr|bool|None, optional) –
The parameter attribute for the learnable bias \(b\). This setting only takes effect when affine is
True. - If set toFalse, no bias parameter will be created. - If set toTrueor a ParamAttr object, a learnable bias parameter will be created.When set to
True, it is equivalent toParamAttr()with default initialization.If set to
None, a learnable bias parameter will be created and initialized to zero.
Default: None. Note: This argument must be passed as a keyword argument.
data_format (str, optional) – Specify the input data format. Support “NCL”, “NCHW”, “NCDHW”, “NLC”, “NHWC” or “NDHWC”. Default: “NCHW”. Note: This argument must be passed as a keyword argument.
name (str|None, optional) – Name for the GroupNorm, default is None. For more information, please refer to api_guide_Name. Note: This argument must be passed as a keyword argument.
- 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: Tensor
)
Tensor
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
(
)
str
extra_repr¶
-
Extra representation of this layer, you can have custom implementation of your own layer.
