forked from mindspore-Ecosystem/mindspore
!31975 Fix docs again
Merge pull request !31975 from wanyiming/code_docs_initcn
This commit is contained in:
commit
9ab981d3b4
|
@ -22,6 +22,7 @@ mindspore.common.initializer
|
||||||
- **str** - `init` 是继承自 `Initializer` 的类的别名,实际使用时会调用相应的类。`init` 的值可以是"normal"、"ones"或"zeros"等。
|
- **str** - `init` 是继承自 `Initializer` 的类的别名,实际使用时会调用相应的类。`init` 的值可以是"normal"、"ones"或"zeros"等。
|
||||||
- **Initializer** - `init` 是继承自 `Initializer` ,用于初始化Tensor的类。
|
- **Initializer** - `init` 是继承自 `Initializer` ,用于初始化Tensor的类。
|
||||||
- **numbers.Number** - 用于初始化Tensor的常量。
|
- **numbers.Number** - 用于初始化Tensor的常量。
|
||||||
|
- **Tensor** - 用于初始化Tensor的Tensor。
|
||||||
|
|
||||||
- **shape** (Union[[tuple, list, int]) - 被初始化的Tensor的shape,默认值为None。
|
- **shape** (Union[[tuple, list, int]) - 被初始化的Tensor的shape,默认值为None。
|
||||||
- **dtype** (mindspore.dtype) – 被初始化的Tensor的数据类型,默认值为 `mindspore.float32` 。
|
- **dtype** (mindspore.dtype) – 被初始化的Tensor的数据类型,默认值为 `mindspore.float32` 。
|
||||||
|
@ -45,7 +46,7 @@ mindspore.common.initializer
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.Normal(sigma=0.01, mean=0.0)
|
.. py:class:: mindspore.common.initializer.Normal(sigma=0.01, mean=0.0)
|
||||||
|
|
||||||
生成一个服从正态分布N(sigma, mean)的随机数组用于初始化Tensor。
|
生成一个服从正态分布 :math:`{N}(\text{sigma}, \text{mean})` 的随机数组用于初始化Tensor。
|
||||||
|
|
||||||
.. math::
|
.. math::
|
||||||
f(x) = \frac{1} {\sqrt{2*π} * sigma}exp(-\frac{(x - mean)^2} {2*{sigma}^2})
|
f(x) = \frac{1} {\sqrt{2*π} * sigma}exp(-\frac{(x - mean)^2} {2*{sigma}^2})
|
||||||
|
@ -57,44 +58,44 @@ mindspore.common.initializer
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.Uniform(scale=0.07)
|
.. py:class:: mindspore.common.initializer.Uniform(scale=0.07)
|
||||||
|
|
||||||
生成一个服从均匀分布U(-scale, scale)的随机数组用于初始化Tensor。
|
生成一个服从均匀分布 :math:`{U}(-\text{scale}, \text{scale})` 的随机数组用于初始化Tensor。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
|
||||||
**scale** (float) - 均匀分布的边界,默认值为0.07。
|
**scale** (float) - 均匀分布的边界,默认值为0.07。
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.HeUniform(negative_slope=0, mode="fan_in", nonlinearity="leaky_relu")
|
.. py:class:: mindspore.common.initializer.HeUniform(negative_slope=0, mode='fan_in', nonlinearity='leaky_relu')
|
||||||
|
|
||||||
生成一个服从HeKaiming均匀分布U(-boundary, boundary)的随机数组用于初始化Tensor,其中:
|
生成一个服从HeKaiming均匀分布 :math:`{U}(-\text{boundary}, \text{boundary})` 的随机数组用于初始化Tensor,其中:
|
||||||
|
|
||||||
.. math::
|
.. math::
|
||||||
boundary = \text{gain} \times \sqrt{\frac{3}{fan\_mode}}
|
boundary = \text{gain} \times \sqrt{\frac{3}{fan\_mode}}
|
||||||
|
|
||||||
其中,gain是一个可选的缩放因子。fan_mode是权重Tensor中输入或输出单元的数量,取决于mode是"fan_in"或是"fan_out"。
|
:math:`gain` 是一个可选的缩放因子。 :math:`fan\_mode` 是权重Tensor中输入或输出单元的数量,取决于 `mode` 是'fan_in'或是'fan_out'。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
|
||||||
- **negative_slope** (int, float, bool) - 本层激活函数的负数区间斜率(仅适用于非线性激活函数"leaky_relu"),默认值为0。
|
- **negative_slope** (int, float, bool) - 本层激活函数的负数区间斜率(仅适用于非线性激活函数'leaky_relu'),默认值为0。
|
||||||
- **mode** (str) - 可选"fan_in"或"fan_out","fan_in"会保留前向传递中权重方差的量级,"fan_out"会保留反向传递的量级,默认为"fan_in"。
|
- **mode** (str) - 可选'fan_in'或'fan_out','fan_in'会保留前向传递中权重方差的量级,'fan_out'会保留反向传递的量级,默认为'fan_in'。
|
||||||
- **nonlinearity** (str) - 非线性激活函数,推荐使用"relu"或"leaky_relu",默认为"leaky_relu"。
|
- **nonlinearity** (str) - 非线性激活函数,推荐使用'relu'或'leaky_relu',默认为'leaky_relu'。
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.HeNormal(negative_slope=0, mode="fan_in", nonlinearity="leaky_relu")
|
.. py:class:: mindspore.common.initializer.HeNormal(negative_slope=0, mode='fan_in', nonlinearity='leaky_relu')
|
||||||
|
|
||||||
生成一个服从HeKaiming正态分布N(0, sigma^2)的随机数组用于初始化Tensor,其中:
|
生成一个服从HeKaiming正态分布 :math:`{N}(0, \text{sigma}^2)` 的随机数组用于初始化Tensor,其中:
|
||||||
|
|
||||||
.. math::
|
.. math::
|
||||||
sigma = \frac{gain} {\sqrt{fan\_mode}}
|
sigma = \frac{gain} {\sqrt{fan\_mode}}
|
||||||
|
|
||||||
其中,gain是一个可选的缩放因子。如果mode是"fan_in",则fan_mode是权重Tensor中输入单元的数量,如果mode是"fan_out",
|
其中, :math:`gain` 是一个可选的缩放因子。如果 `mode` 是'fan_in',则 :math:`fan\_mode` 是权重Tensor中输入单元的数量,如果 `mode` 是'fan_out',
|
||||||
fan_mode是权重Tensor中输出单元的数量。
|
:math:`fan\_mode` 是权重Tensor中输出单元的数量。
|
||||||
|
|
||||||
HeUniform 算法的详细信息,请查看 https://arxiv.org/abs/1502.01852。
|
HeUniform 算法的详细信息,请查看 https://arxiv.org/abs/1502.01852。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
|
||||||
- **negative_slope** (int, float, bool) - 本层激活函数的负数区间斜率(仅适用于非线性激活函数"leaky_relu"),默认值为0。
|
- **negative_slope** (int, float, bool) - 本层激活函数的负数区间斜率(仅适用于非线性激活函数'leaky_relu'),默认值为0。
|
||||||
- **mode** (str) - 可选"fan_in"或"fan_out","fan_in"会保留前向传递中权重方差的量级,"fan_out"会保留反向传递的量级,默认为"fan_in"。
|
- **mode** (str) - 可选'fan_in'或'fan_out','fan_in'会保留前向传递中权重方差的量级,'fan_out'会保留反向传递的量级,默认为'fan_in'。
|
||||||
- **nonlinearity** (str) - 非线性激活函数,推荐使用"relu"或"leaky_relu",默认为"leaky_relu"。
|
- **nonlinearity** (str) - 非线性激活函数,推荐使用'relu'或'leaky_relu',默认为'leaky_relu'。
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.XavierUniform(gain=1)
|
.. py:class:: mindspore.common.initializer.XavierUniform(gain=1)
|
||||||
|
|
||||||
|
@ -136,7 +137,7 @@ mindspore.common.initializer
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.Identity(**kwargs)
|
.. py:class:: mindspore.common.initializer.Identity(**kwargs)
|
||||||
|
|
||||||
生成一个2维的单位阵用于初始化Tensor。
|
生成一个2维的单位矩阵用于初始化Tensor。
|
||||||
|
|
||||||
**异常:**
|
**异常:**
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ mindspore.common.initializer
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.Sparse(sparsity, sigma=0.01)
|
.. py:class:: mindspore.common.initializer.Sparse(sparsity, sigma=0.01)
|
||||||
|
|
||||||
生成一个2维的稀疏矩阵用于初始化Tensor。矩阵非0的位置的值服从正态分布N(0, 0.01)。
|
生成一个2维的稀疏矩阵用于初始化Tensor。矩阵非0的位置的值服从正态分布 :math:`N(0, 0.01)` 。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ mindspore.common.initializer
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.Dirac(groups=1)
|
.. py:class:: mindspore.common.initializer.Dirac(groups=1)
|
||||||
|
|
||||||
利用Dirac delta函数生成一个array用于初始化Tensor。这种初始化方式将会保留卷积层的输入。对于group
|
利用Dirac delta函数生成一个矩阵用于初始化Tensor。这种初始化方式将会保留卷积层的输入。对于group
|
||||||
卷积,通道的每个分组会被分别保留。
|
卷积,通道的每个分组会被分别保留。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
@ -169,14 +170,14 @@ mindspore.common.initializer
|
||||||
|
|
||||||
**异常:**
|
**异常:**
|
||||||
|
|
||||||
- **ValueError** - groups不在[3, 4, 5]的范围内。
|
- **ValueError** - 被初始化的Tensor的维度不在[3, 4, 5]的范围内。
|
||||||
- **ValueError** - 初始化的Tensor的第一个维度不能被groups整除。
|
- **ValueError** - 初始化的Tensor的第一个维度不能被groups整除。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.Orthogonal(gain=1.)
|
.. py:class:: mindspore.common.initializer.Orthogonal(gain=1.)
|
||||||
|
|
||||||
生成一个(半)正交矩阵用于初始化Tensor。被初始化的Tensor的维度至少为2。
|
生成一个正交或半正交矩阵用于初始化Tensor。被初始化的Tensor的维度至少为2。
|
||||||
如果维度大于2,多余的维度将会被展平。
|
如果维度大于2,多余的维度将会被展平。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
@ -188,25 +189,25 @@ mindspore.common.initializer
|
||||||
- **ValueError** - 被初始化的Tensor的维度小于2。
|
- **ValueError** - 被初始化的Tensor的维度小于2。
|
||||||
|
|
||||||
|
|
||||||
.. py:class:: mindspore.common.initializer.VarianceScaling(scale=1.0, mode="fan_in", distribution="truncated_normal")
|
.. py:class:: mindspore.common.initializer.VarianceScaling(scale=1.0, mode='fan_in', distribution='truncated_normal')
|
||||||
|
|
||||||
生成一个随机的array用于初始化Tensor。
|
生成一个随机的矩阵用于初始化Tensor。
|
||||||
当distribution是"truncated_normal"或者"untruncated_normal"时,array中的值将服从均值为0,标准差
|
当 `distribution` 是'truncated_normal'或者'untruncated_normal'时,矩阵中的值将服从均值为0,标准差
|
||||||
为 :math:`stddev = sqrt(scale/n)` 的截断或者非截断正太分布。如果mode是"fan_in", :math:`n` 是输入单元的数量;
|
为 :math:`stddev = \sqrt{\scale{6}{n}}` 的截断或者非截断正太分布。如果 `mode` 是'fan_in', :math:`n` 是输入单元的数量;
|
||||||
如果mode是"fan_out", :math:`n` 是输出单元的数量;如果mode是"fan_avg", :math:`n` 是输入输出单元数量的均值。
|
如果 `mode` 是'fan_out', :math:`n` 是输出单元的数量;如果 `mode` 是'fan_avg', :math:`n` 是输入输出单元数量的均值。
|
||||||
当distribution是"uniform"时,array中的值将服从均匀分布[`-sqrt(3*scale/n)`, `sqrt(3*scale/n)`]。
|
当 `distribution` 是'uniform'时,矩阵中的值将服从均匀分布 :math:`[-\sqrt{\scale{3*scale}{n}}, \sqrt{\scale{3*scale}{n}}]`。
|
||||||
|
|
||||||
**参数:**
|
**参数:**
|
||||||
|
|
||||||
- **scale** (float) - 比例因子,默认值为1.0。
|
- **scale** (float) - 比例因子,默认值为1.0。
|
||||||
- **mode** (str) - 其值应为"fan_in","fan_out"或者"fan_avg",默认值为"fan_in"。
|
- **mode** (str) - 其值应为'fan_in','fan_out'或者'fan_avg',默认值为'fan_in'。
|
||||||
- **distribution** (str) - 用于采样的分布类型。它可以是"uniform","truncated_normal"或"untruncated_normal",默认值为"truncated_normal"。
|
- **distribution** (str) - 用于采样的分布类型。它可以是 'uniform','truncated_normal'或'untruncated_normal',默认值为'truncated_normal'。
|
||||||
|
|
||||||
**异常:**
|
**异常:**
|
||||||
|
|
||||||
- **ValueError** - scale小于等于0。
|
- **ValueError** - `scale` 小于等于0。
|
||||||
- **ValueError** - mode不是"fan_in","fan_out"或者"fan_avg"。
|
- **ValueError** - `mode` 不是'fan_in','fan_out'或者'fan_avg'。
|
||||||
- **ValueError** - distribution不是"truncated_normal","untruncated_normal"或者"uniform"。
|
- **ValueError** - `distribution` 不是'truncated_normal','untruncated_normal'或者'uniform'。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -282,9 +282,9 @@ class HeUniform(Initializer):
|
||||||
(only used when `nonlinearity` is 'leaky_relu'). Default: 0.
|
(only used when `nonlinearity` is 'leaky_relu'). Default: 0.
|
||||||
mode (str): Either 'fan_in' or 'fan_out'. Choosing 'fan_in' preserves the magnitude of the
|
mode (str): Either 'fan_in' or 'fan_out'. Choosing 'fan_in' preserves the magnitude of the
|
||||||
variance of the weights in the forward pass. Choosing 'fan_out' preserves the magnitudes
|
variance of the weights in the forward pass. Choosing 'fan_out' preserves the magnitudes
|
||||||
in the backwards pass. Default: fan_in.
|
in the backwards pass. Default: 'fan_in'.
|
||||||
nonlinearity (str): The non-linear function, recommended to use only with 'relu' or 'leaky_relu'.
|
nonlinearity (str): The non-linear function, recommended to use only with 'relu' or 'leaky_relu'.
|
||||||
Default: leaky_relu.
|
Default: 'leaky_relu'.
|
||||||
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
@ -328,9 +328,9 @@ class HeNormal(Initializer):
|
||||||
(only used when `nonlinearity` is 'leaky_relu'). Default: 0.
|
(only used when `nonlinearity` is 'leaky_relu'). Default: 0.
|
||||||
mode (str): Either 'fan_in' or 'fan_out'. Choosing 'fan_in' preserves the magnitude of the
|
mode (str): Either 'fan_in' or 'fan_out'. Choosing 'fan_in' preserves the magnitude of the
|
||||||
variance of the weights in the forward pass. Choosing 'fan_out' preserves the magnitudes
|
variance of the weights in the forward pass. Choosing 'fan_out' preserves the magnitudes
|
||||||
in the backwards pass. Default: fan_in.
|
in the backwards pass. Default: 'fan_in'.
|
||||||
nonlinearity (str): The non-linear function, recommended to use only with 'relu' or 'leaky_relu'.
|
nonlinearity (str): The non-linear function, recommended to use only with 'relu' or 'leaky_relu'.
|
||||||
Default: leaky_relu.
|
Default: 'leaky_relu'.
|
||||||
|
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
@ -445,7 +445,7 @@ class Dirac(Initializer):
|
||||||
groups (int): The number of group in convolution layer. Default: 1.
|
groups (int): The number of group in convolution layer. Default: 1.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If the value of group is not in [3, 4, 5].
|
ValueError: If the dimension of the initialized tensor is not in [3, 4, 5].
|
||||||
ValueError: The first dimension of the initialized tensor cannot be divisible by group.
|
ValueError: The first dimension of the initialized tensor cannot be divisible by group.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
@ -536,12 +536,12 @@ class Orthogonal(Initializer):
|
||||||
class VarianceScaling(Initializer):
|
class VarianceScaling(Initializer):
|
||||||
r"""
|
r"""
|
||||||
Generates an random array with scaling in order to initialize a tensor.
|
Generates an random array with scaling in order to initialize a tensor.
|
||||||
When distribution is truncated_normal or untruncated_normal, the value will be sampled from truncated or
|
When `distribution` is 'truncated_normal' or 'untruncated_normal', the value will be sampled from truncated or
|
||||||
untruncated normal distribution with a mean of 0 and a scaled standard deviation :math:`stddev = sqrt(scale/n)`.
|
untruncated normal distribution with a mean of 0 and a scaled standard deviation
|
||||||
:math:`n` will be the number of input units if mode is fan_in, the number of output units if mode is fan_out,
|
:math:`stddev = \sqrt{\scale{6}{n}}`. :math:`n` will be the number of input units if `mode` is 'fan_in',
|
||||||
the average of fan_in and fan_out if mode is fan_avg.
|
the number of output units if `mode` is 'fan_out', the average of 'fan_in' and 'fan_out' if `mode` is 'fan_avg'.
|
||||||
When distribution is uniform, the value will be sampled from a uniform distribution within the limit of
|
When `distribution` is 'uniform', the value will be sampled from a uniform distribution within the limit of
|
||||||
[`-sqrt(3*scale/n)`, `sqrt(3*scale/n)`].
|
:math:`[-\sqrt{\scale{3*scale}{n}}, \sqrt{\scale{3*scale}{n}}]`.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
scale (float): The scaling factor. Default: 1.0.
|
scale (float): The scaling factor. Default: 1.0.
|
||||||
|
@ -550,9 +550,9 @@ class VarianceScaling(Initializer):
|
||||||
'uniform', 'truncated_normal' or 'untruncated_normal'. Default: 'truncated_normal'.
|
'uniform', 'truncated_normal' or 'untruncated_normal'. Default: 'truncated_normal'.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
ValueError: If scale is not greater than 0.
|
ValueError: If `scale` is not greater than 0.
|
||||||
ValueError: If mode is not fan_in, fan_out or fan_avg.
|
ValueError: If `mode` is not 'fan_in', 'fan_out' or 'fan_avg'.
|
||||||
ValueError: If distribution is not uniform, truncated_normal or untruncated_normal.
|
ValueError: If `distribution` is not 'uniform', 'truncated_normal' or 'untruncated_normal'.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
>>> import mindspore
|
>>> import mindspore
|
||||||
|
@ -695,6 +695,8 @@ def initializer(init, shape=None, dtype=mstype.float32):
|
||||||
|
|
||||||
- `numbers.Number`: The `Constant` will be called to initialize tensor.
|
- `numbers.Number`: The `Constant` will be called to initialize tensor.
|
||||||
|
|
||||||
|
- `Tensor`: The tensor will be called to initialize tensor.
|
||||||
|
|
||||||
shape (Union[tuple, list, int]): The shape of the initialized tensor. Default: None.
|
shape (Union[tuple, list, int]): The shape of the initialized tensor. Default: None.
|
||||||
dtype (:class:`mindspore.dtype`): The type of data in initialized tensor. Default: mindspore.float32.
|
dtype (:class:`mindspore.dtype`): The type of data in initialized tensor. Default: mindspore.float32.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue