mindspore/docs/api/api_python/nn/mindspore.nn.BatchNorm1d.rst

43 lines
3.0 KiB
ReStructuredText
Raw Normal View History

mindspore.nn.BatchNorm1d
=========================
.. py:class:: mindspore.nn.BatchNorm1d(num_features,eps=1e-5,momentum=0.9,affine=True,gamma_init='ones',beta_init='zeros',moving_mean_init='zeros',moving_var_init='ones',use_batch_statistics=None)
对输入的二维数据进行批归一化(Batch Normalization Layer)。
在二维输入mini-batch 一维输入)上应用批归一化,避免内部协变量偏移。归一化在卷积网络中被广泛的应用。请见论文 `Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift <https://arxiv.org/abs/1502.03167>`_
使用mini-batch数据和学习参数进行训练计算公式如下。
.. math::
y = \frac{x - \mathrm{E}[x]}{\sqrt{\mathrm{Var}[x] + \epsilon}} * \gamma + \beta
.. note::
BatchNorm的实现在图模式和PyNative模式下是不同的因此不建议在网络初始化后更改其模式。
**参数:**
- **num_features** (int) - 指定输入Tensor的通道数量输入Tensor的size为 :math:`(N, C)`
- **eps** (float) - :math:`\epsilon` 加在分母上的值以确保数值稳定。默认值1e-5。
- **momentum** (float) - 动态均值和动态方差所使用的动量。默认值0.9。
- **affine** (bool) - bool类型。设置为True时可学习到 :math:`\gamma`:math:`\beta` 值。默认值True。
- **gamma_init** (Union[Tensor, str, Initializer, numbers.Number]) - :math:`\gamma` 参数的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'等。默认值:'ones'。
- **beta_init** (Union[Tensor, str, Initializer, numbers.Number]) - :math:`\beta` 参数的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'等。默认值:'zeros'。
- **moving_mean_init** (Union[Tensor, str, Initializer, numbers.Number]) - 动态平均值的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'等。默认值:'zeros'。
- **moving_var_init** (Union[Tensor, str, Initializer, numbers.Number]) - 动态方差的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'等。默认值:'ones'。
- **use_batch_statistics** (bool) - 如果为True则使用当前批次数据的平均值和方差值。如果为False则使用指定的平均值和方差值。如果为None训练时将使用当前批次数据的均值和方差并更新动态均值和方差验证过程将直接使用动态均值和方差。默认值None。
**输入:**
- **x** (Tensor)输入shape为 :math:`(N, C_{in})` 的Tensor。
**输出:**
Tensor归一化后的Tensorshape为 :math:`(N, C_{out})`
**异常:**
- **TypeError** - `num_features` 不是整数。
- **TypeError** - `eps` 不是浮点数。
- **ValueError** - `num_features` 小于1。
- **ValueError** - `momentum` 不在范围[0, 1]内。