mindspore.mint.nn.GroupNorm ================================= .. image:: https://mindspore-website.obs.cn-north-4.myhuaweicloud.com/website-images/master/resource/_static/logo_source.svg :target: https://gitee.com/mindspore/mindspore/blob/master/docs/api/api_python/mint/mindspore.mint.nn.GroupNorm.rst :alt: 查看源文件 .. py:class:: mindspore.mint.nn.GroupNorm(num_groups, num_channels, eps=1e-05, affine=True, dtype=None) 在mini-batch输入上进行组归一化。 Group Normalization被广泛用于递归神经网络中。适用单个训练用例的mini-batch输入归一化,详见论文 `Group Normalization <https://arxiv.org/pdf/1803.08494.pdf>`_ 。 Group Normalization把通道划分为组,然后计算每一组之内的均值和方差,以进行归一化。其中 :math:`\gamma` 是通过训练学习出的scale值,:math:`\beta` 是通过训练学习出的shift值。 公式如下, .. math:: y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta 其中, :math:`\gamma` 为 `weight`, :math:`\beta` 为 `bias`, :math:`\epsilon` 为 `eps`。 参数: - **num_groups** (int) - 沿通道维度待划分的组数。 - **num_channels** (int) - 输入的通道维度数。 - **eps** (float, 可选) - 添加到分母中的值,以确保数值稳定。默认值: ``1e-05`` 。 - **affine** (bool, 可选) - 当被设置为 ``True`` 时,参数 :math:`\gamma` 和 :math:`\beta` 是可学习的。默认值: ``True`` 。 - **dtype** (:class:`mindspore.dtype`, 可选) - Parameter的类型。默认值: ``None`` 。 输入: - **input** (Tensor) - 输入特征的shape为 :math:`(N, C, *)`,其中 :math:`*` 任意数量的附加维度。 输出: Tensor,被标准化和缩放偏移后的Tensor,具有与 `input` 相同的shape和数据类型。 异常: - **TypeError** - `num_groups` 或 `num_channels` 不是int。 - **TypeError** - `eps` 不是float。 - **TypeError** - `affine` 不是bool。 - **ValueError** - `num_groups` 或 `num_channels` 小于1。 - **ValueError** - `num_channels` 未被 `num_groups` 整除。