tf.keras.layers.GroupNormalization
Stay organized with collections
Save and categorize content based on your preferences.
Group normalization layer.
Inherits From: Layer
, Operation
tf.keras.layers.GroupNormalization(
groups=32,
axis=-1,
epsilon=0.001,
center=True,
scale=True,
beta_initializer='zeros',
gamma_initializer='ones',
beta_regularizer=None,
gamma_regularizer=None,
beta_constraint=None,
gamma_constraint=None,
**kwargs
)
Group Normalization divides the channels into groups and computes
within each group the mean and variance for normalization.
Empirically, its accuracy is more stable than batch norm in a wide
range of small batch sizes, if learning rate is adjusted linearly
with batch sizes.
Relation to Layer Normalization:
If the number of groups is set to 1, then this operation becomes nearly
identical to Layer Normalization (see Layer Normalization docs for details).
Relation to Instance Normalization:
If the number of groups is set to the input dimension (number of groups is
equal to number of channels), then this operation becomes identical to
Instance Normalization. You can achieve this via groups=-1
.
Args |
groups
|
Integer, the number of groups for Group Normalization. Can be in
the range [1, N] where N is the input dimension. The input
dimension must be divisible by the number of groups.
Defaults to 32.
|
axis
|
Integer or List/Tuple. The axis or axes to normalize across.
Typically, this is the features axis/axes. The left-out axes are
typically the batch axis/axes. -1 is the last dimension in the
input. Defaults to -1 .
|
epsilon
|
Small float added to variance to avoid dividing by zero.
Defaults to 1e-3.
|
center
|
If True , add offset of beta to normalized tensor.
If False , beta is ignored. Defaults to True .
|
scale
|
If True , multiply by gamma . If False , gamma is not used.
When the next layer is linear (also e.g. relu ), this can be
disabled since the scaling will be done by the next layer.
Defaults to True .
|
beta_initializer
|
Initializer for the beta weight. Defaults to zeros.
|
gamma_initializer
|
Initializer for the gamma weight. Defaults to ones.
|
beta_regularizer
|
Optional regularizer for the beta weight. None by
default.
|
gamma_regularizer
|
Optional regularizer for the gamma weight. None by
default.
|
beta_constraint
|
Optional constraint for the beta weight.
None by default.
|
gamma_constraint
|
Optional constraint for the gamma weight. None by
default. Input shape: Arbitrary. Use the keyword argument
input_shape (tuple of integers, does not include the samples
axis) when using this layer as the first layer in a model.
Output shape: Same shape as input.
|
**kwargs
|
Base layer keyword arguments (e.g. name and dtype ).
|
Reference:
Attributes |
input
|
Retrieves the input tensor(s) of a symbolic operation.
Only returns the tensor(s) corresponding to the first time
the operation was called.
|
output
|
Retrieves the output tensor(s) of a layer.
Only returns the tensor(s) corresponding to the first time
the operation was called.
|
Methods
from_config
View source
@classmethod
from_config(
config
)
Creates a layer from its config.
This method is the reverse of get_config
,
capable of instantiating the same layer from the config
dictionary. It does not handle layer connectivity
(handled by Network), nor weights (handled by set_weights
).
Args |
config
|
A Python dictionary, typically the
output of get_config.
|
Returns |
A layer instance.
|
symbolic_call
View source
symbolic_call(
*args, **kwargs
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-06-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.layers.GroupNormalization\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/layers/normalization/group_normalization.py#L10-L219) |\n\nGroup normalization layer.\n\nInherits From: [`Layer`](../../../tf/keras/Layer), [`Operation`](../../../tf/keras/Operation) \n\n tf.keras.layers.GroupNormalization(\n groups=32,\n axis=-1,\n epsilon=0.001,\n center=True,\n scale=True,\n beta_initializer='zeros',\n gamma_initializer='ones',\n beta_regularizer=None,\n gamma_regularizer=None,\n beta_constraint=None,\n gamma_constraint=None,\n **kwargs\n )\n\nGroup Normalization divides the channels into groups and computes\nwithin each group the mean and variance for normalization.\nEmpirically, its accuracy is more stable than batch norm in a wide\nrange of small batch sizes, if learning rate is adjusted linearly\nwith batch sizes.\n\nRelation to Layer Normalization:\nIf the number of groups is set to 1, then this operation becomes nearly\nidentical to Layer Normalization (see Layer Normalization docs for details).\n\nRelation to Instance Normalization:\nIf the number of groups is set to the input dimension (number of groups is\nequal to number of channels), then this operation becomes identical to\nInstance Normalization. You can achieve this via `groups=-1`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `groups` | Integer, the number of groups for Group Normalization. Can be in the range `[1, N]` where N is the input dimension. The input dimension must be divisible by the number of groups. Defaults to 32. |\n| `axis` | Integer or List/Tuple. The axis or axes to normalize across. Typically, this is the features axis/axes. The left-out axes are typically the batch axis/axes. -1 is the last dimension in the input. Defaults to `-1`. |\n| `epsilon` | Small float added to variance to avoid dividing by zero. Defaults to 1e-3. |\n| `center` | If `True`, add offset of `beta` to normalized tensor. If `False`, `beta` is ignored. Defaults to `True`. |\n| `scale` | If `True`, multiply by `gamma`. If `False`, `gamma` is not used. When the next layer is linear (also e.g. `relu`), this can be disabled since the scaling will be done by the next layer. Defaults to `True`. |\n| `beta_initializer` | Initializer for the beta weight. Defaults to zeros. |\n| `gamma_initializer` | Initializer for the gamma weight. Defaults to ones. |\n| `beta_regularizer` | Optional regularizer for the beta weight. None by default. |\n| `gamma_regularizer` | Optional regularizer for the gamma weight. None by default. |\n| `beta_constraint` | Optional constraint for the beta weight. None by default. |\n| `gamma_constraint` | Optional constraint for the gamma weight. None by default. Input shape: Arbitrary. Use the keyword argument `input_shape` (tuple of integers, does not include the samples axis) when using this layer as the first layer in a model. Output shape: Same shape as input. |\n| `**kwargs` | Base layer keyword arguments (e.g. `name` and `dtype`). |\n\n\u003cbr /\u003e\n\n#### Reference:\n\n- [Yuxin Wu \\& Kaiming He, 2018](https://arxiv.org/abs/1803.08494)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | Retrieves the input tensor(s) of a symbolic operation. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n| `output` | Retrieves the output tensor(s) of a layer. \u003cbr /\u003e Only returns the tensor(s) corresponding to the *first time* the operation was called. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_config`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L191-L213) \n\n @classmethod\n from_config(\n config\n )\n\nCreates a layer from its config.\n\nThis method is the reverse of `get_config`,\ncapable of instantiating the same layer from the config\ndictionary. It does not handle layer connectivity\n(handled by Network), nor weights (handled by `set_weights`).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|----------------------------------------------------------|\n| `config` | A Python dictionary, typically the output of get_config. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A layer instance. ||\n\n\u003cbr /\u003e\n\n### `symbolic_call`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/operation.py#L58-L70) \n\n symbolic_call(\n *args, **kwargs\n )"]]