!32450 optimizes the documentation of chinese API of BCELoss,BatchNorm2d,DiceLoss,etc

Merge pull request !32450 from zhangfanghe/code_docs_zfh_r17_401
This commit is contained in:
i-robot 2022-04-02 08:32:32 +00:00 committed by Gitee
commit ab4657d943
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 87 additions and 78 deletions

View File

@ -37,7 +37,7 @@ mindspore.nn.BCELoss
**输出:**
Tensor或Scalar如果 `reduction` 为'None'则输出是Tensorshape与 `logits` 相同。否则输出为Scalar。
Tensor,数据类型与 `logits` 相同。如果 `reduction` 为'none',则shape与 `logits` 相同。否则输出为Scalar的Tensor。
**异常:**

View File

@ -13,13 +13,13 @@ mindspore.nn.BatchNorm2d
.. note::
BatchNorm的实现在图模式和PyNative模式下是不同的因此不建议在网络初始化后更改其模式。
需要注意的是,更新 `moving_mean``moving_var` 的公式为:
需要注意的是,更新 :math:`moving\_mean` 和 :math:`moving\_var` 的公式为:
.. math::
\text{moving_mean}=\text{moving_mean*momentum}+μ_β\text{*(1momentum)}\\
\text{moving_var}=\text{moving_var*momentum}+σ^2_β\text{*(1momentum)}
其中, :math:`moving_mean, moving_var` 分别是更新后的均值和方差, :math:`μ_β, σ^2_β` 是每一批的数据的观测值(均值和方差)。
其中, :math:`moving\_mean` 是更新后的均值, :math:`moving\_var` 是更新后的方差, :math:`μ_β, σ^2_β` 是每一批的数据的观测值(均值和方差)。
**参数:**

View File

@ -24,7 +24,7 @@ mindspore.nn.DiceLoss
**输出:**
Tensorshape为每样本采样的Dice loss的Tensor。
Tensorshape为每样本采样的Dice系数的Tensor。
**异常:**

View File

@ -10,7 +10,7 @@ mindspore.nn.Dropout
论文 `Dropout: A Simple Way to Prevent Neural Networks from Overfitting <http://www.cs.toronto.edu/~rsalakhu/papers/srivastava14a.pdf>`_ 中提出了该技术,并证明其能有效地减少过度拟合,防止神经元共适应。更多详细信息,请参见 `Improving neural networks by preventing co-adaptation of feature detectors <https://arxiv.org/pdf/1207.0580.pdf>`_
.. note::
每个通道将在每次构造调用时独立归零
训练过程中每步对同一通道(或神经元)独立进行丢弃
**参数:**

View File

@ -5,7 +5,7 @@ mindspore.nn.Embedding
嵌入层。
该模块常被用做存储词嵌入,并使用索引检索它们。该模块的输入是一个索引列表,输出是对应的词嵌入
用于存储词向量并使用索引进行检索根据输入Tensor中的id`embedding_table` 中查询对应的embedding向量。当输入为id组成的序列时输出为对应embedding向量构成的矩阵
.. note::
`use_one_hot` 等于True时x的类型必须是mindpore.int32。
@ -15,7 +15,7 @@ mindspore.nn.Embedding
- **vocab_size** (int) - 词典的大小。
- **embedding_size** (int) - 每个嵌入向量的大小。
- **use_one_hot** (bool) - 指定是否使用one-hot形式。默认值False。
- **embedding_table** (Union[Tensor, str, Initializer, numbers.Number]) embedding_table的初始化方法。当指定为字符串字符串取值请参见类 `Initializer` 。默认值:'normal'。
- **embedding_table** (Union[Tensor, str, Initializer, numbers.Number]) embedding_table的初始化方法。当指定为字符串字符串取值请参见类 `mindspore.common.initializer` 。默认值:'normal'。
- **dtype** (mindspore.dtype) - x的数据类型。默认值mindspore.float32。
- **padding_idx** (int, None) - 将 `padding_idx` 对应索引所输出的嵌入向量用零填充。默认值None。该功能已停用。

View File

@ -17,7 +17,7 @@ mindspore.nn.EmbeddingLookup
- **vocab_size** (int) - 嵌入词典的大小。
- **embedding_size** (int) - 每个嵌入向量的大小。
- **param_init** (Union[Tensor, str, Initializer, numbers.Number]) - embedding_table的初始化方法。当指定为字符串字符串取值请参见类 `Initializer` 。默认值:'normal'。
- **target** (str) - 指定执行操作的'target'。取值范围为['DEVICE', 'CPU']。默认值:'CPU'。
- **target** (str) - 指定执行操作的'target'。取值范围为['Ascend', 'GPU', 'CPU']。默认值:'CPU'。
- **slice_mode** (str) - semi_auto_parallel或auto_parallel模式下的切片方式。该值必须通过nn.EmbeddingLookup获得。默认值nn.EmbeddingLookup.BATCH_SLICE。
- **manual_shapes** (tuple) - 字段切片模式下的伴随数组accompaniment array默认值None。
- **max_norm** (Union[float, None]) - 最大剪切值。数据类型必须为float16、float32或None。默认值None。
@ -30,7 +30,7 @@ mindspore.nn.EmbeddingLookup
**输出:**
Tensorshape为 :math:`(z_1, z_2, ..., z_N)`tensor。
Tensorshape为 :math:`(z_1, z_2, ..., z_N)`Tensor。
**异常:**

View File

@ -7,7 +7,7 @@ mindspore.nn.FocalLoss
解决了类别不平衡的问题。
论文 `Focal Loss for Dense Object Detection <https://arxiv.org/pdf/1708.02002.pdf>`_ 中提出的loss函数提高了图像目标检测的效果。
FocalLoss函数在论文 `Focal Loss for Dense Object Detection <https://arxiv.org/pdf/1708.02002.pdf>`_ 中提出提高了图像目标检测的效果。
函数如下:

View File

@ -20,12 +20,12 @@ mindspore.nn.GroupNorm
- **num_channels** (int) - 输入的通道数。
- **eps** (float) - 添加到分母中的值以确保数值稳定。默认值1e-5。
- **affine** (bool) - Bool类型当设置为True时给该层添加可学习的仿射变换参数即gama与beta。默认值True。
- **gamma_init** (Union[Tensor, str, Initializer, numbers.Number]) - gamma参数的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'、'xavier_uniform'、'he_uniform'等。默认值:'ones'。如果gamma_init是Tensor则shape必须为[num_channels]
- **beta_init** (Union[Tensor, str, Initializer, numbers.Number]) - beta参数的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'、'xavier_uniform'、'he_uniform'等。默认值:'zeros'如果gamma_init是Tensor则shape必须为[num_channels]
- **gamma_init** (Union[Tensor, str, Initializer, numbers.Number]) - gamma参数的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'、'xavier_uniform'、'he_uniform'等。默认值:'ones'。如果gamma_init是Tensor则shape必须为 :math:`(num\_channels)`
- **beta_init** (Union[Tensor, str, Initializer, numbers.Number]) - beta参数的初始化方法。str的值引用自函数 `mindspore.common.initializer` ,包括'zeros'、'ones'、'xavier_uniform'、'he_uniform'等。默认值:'zeros'如果gamma_init是Tensor则shape必须为 :math:`(num\_channels)`
**输入:**
- **x** (Tensor) - shape为 `(N, C, H, W)` 的特征输入。
- **x** (Tensor) - shape为 :math:`(N, C, H, W)` 的特征输入。
**输出:**
@ -33,7 +33,7 @@ mindspore.nn.GroupNorm
**异常:**
- **TypeError** - `num_groups``num_channels` 不是整数
- **TypeError** - `num_groups``num_channels` 不是int
- **TypeError** - `eps` 不是float。
- **TypeError** - `affine` 不是bool。
- **ValueError** - `num_groups``num_channels` 小于1。

View File

@ -32,4 +32,8 @@ mindspore.nn.LossBase
**参数:**
- **x** (Tensor) - 输入数据任意维度的Tensor。
- **weights** (Union[float, Tensor]) - 可选值要么rank为0要么rank与输入相同并且必须可广播到输入所有维度必须为 `1` ,或与相应输入的维度相同)。默认值: 1.0。
- **weights** (Union[float, Tensor]) - 可选值要么rank为0要么rank与输入相同并且必须可广播到输入所有维度必须为 `1` ,或与相应输入的维度相同)。默认值: 1.0。
**返回:**
返回加权损失。

View File

@ -8,7 +8,7 @@ mindspore.nn.RNN
对输入序列中的每个元素,每层的计算公式如下:
.. math::
h_t = \tanh(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})
h_t = activation(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})
这里的 :math:`h_t` 是在 `t` 时刻的隐藏状态, :math:`x_t`是在 `t` 时刻的输入, :math:`h_{(t-1)}` 是上一层在 :math:`t-1` 时刻的隐藏状态,或初始隐藏状态。如果 `nonlinearity` 是'relu',则使用 :math:`\text{relu}` 而不是 :math:`\tanh`
@ -24,17 +24,17 @@ mindspore.nn.RNN
- **bidirectional** (bool) - 指定是否为双向RNN如果bidirectional=True则num_directions=2否则为1。默认值False。
**输入:**
- **x** (Tensor) - 数据类型为mindspore.float32或mindspore.float16shape为(seq_len, batch_size, `input_size`)或(batch_size, seq_len, `input_size`)的Tensor。
- **hx** (Tensor) - 数据类型为mindspore.float32或mindspore.float16shape为(num_directions * `num_layers`, batch_size, `hidden_size`)的Tensor。 `hx` 的数据类型与 `x` 相同。
- **seq_length** (Tensor) - 输入batch的序列长度Tensor的shape为 `(batch_size)` 。此输入指明真实的序列长度,以避免使用填充后的元素计算隐藏状态,影响最后的输出。当**x**被填充元素时建议使用此输入。默认值None。
- **x** (Tensor) - 数据类型为mindspore.float32或mindspore.float16shape为 :math:`(seq\_len, batch\_size, input\_size)`:math:`(batch\_size, seq\_len, input\_size)` 的Tensor。
- **hx** (Tensor) - 数据类型为mindspore.float32或mindspore.float16shape为 :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)` 的Tensor。 `hx` 的数据类型与 `x` 相同。
- **seq_length** (Tensor) - 输入batch的序列长度Tensor的shape为 :math:`(batch\_size)` 。此输入指明真实的序列长度,以避免使用填充后的元素计算隐藏状态,影响最后的输出。当 `x` 被填充元素时建议使用此输入。默认值None。
**输出:**
Tuple包含(`output`, `hx_n`)的tuple。
- **output** (Tensor) - shape为(seq_len, batch_size, num_directions * `hidden_size`)或(batch_size, seq_len, num_directions * `hidden_size`)的Tensor。
- **hx_n** (Tensor) - shape为(num_directions * `num_layers` , batch_size, `hidden_size`)的Tensor。
- **output** (Tensor) - shape为 :math:`(seq\_len, batch\_size, num\_directions * hidden\_size)`:math:`(batch\_size, seq\_len, num\_directions * hidden\_size)` 的Tensor。
- **hx_n** (Tensor) - shape为 :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)` 的Tensor。
**异常:**

View File

@ -3,7 +3,7 @@ mindspore.nn.RNNCell
.. py:class:: mindspore.nn.RNNCell(input_size: int, hidden_size: int, has_bias: bool = True, nonlinearity: str = 'tanh')
用于定义循环神经网络RNN的一个单元激活函数是tanh或relu。
循环神经网络单元激活函数是tanh或relu。
.. math::
h_t = \tanh(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})
@ -20,13 +20,13 @@ mindspore.nn.RNNCell
- **nonlinearity** (str) - 用于选择非线性激活函数。取值可以是'tanh'或'relu'。默认值:'tanh'。
**输入:**
- **x** (Tensor) - 输入Tensor其shape为(batch_size, `input_size`)
- **hx** (Tensor) - 输入Tensor其数据类型为mindspore.float32及shape为(batch_size, `hidden_size`)`hx` 的数据类型与 `x` 相同。
- **x** (Tensor) - 输入Tensor其shape为 :math:`(batch\_size, input\_size)`
- **hx** (Tensor) - 输入Tensor其数据类型为mindspore.float32及shape为 :math:`(batch\_size, hidden\_size)` `hx` 的数据类型与 `x` 相同。
**输出:**
- **hx'** (Tensor) - shape为(batch_size, `hidden_size`)的Tensor。
- **hx'** (Tensor) - shape为 :math:`(batch\_size, hidden\_size)` 的Tensor。
**异常:**

View File

@ -12,7 +12,7 @@ mindspore.nn.Triu
**输入:**
- **x** (Tensor) - Triu的输入任意维度的Tensor其数据类型为Number
- **x** (Tensor) - Triu的输入任意维度的Tensor其数据类型为数值型
- **k** (int) - 对角线的索引。默认值0。
**输出:**

View File

@ -1 +1 @@
- **lr** - 可选。如果键中存在"lr",则使用对应的值作为学习率。如果没有,则使用优化器中配置`learning_rate` 作为学习率。支持固定和动态学习率。
- **lr** - 可选。如果键中存在"lr",则使用对应的值作为学习率。如果没有,则使用优化器中的参数 `learning_rate` 作为学习率。支持固定和动态学习率。

View File

@ -1 +1 @@
- **order_params** - 可选。对应值是预期的参数更新顺序。当使用参数分组功能时,通常使用该配置项保持 `parameters` 的顺序以提升性能。如果键中存在"order_params",则会忽略该组配置中的其他键。"order_params"中的参数必须在某一组 `params` 参数中。
- **order_params** - 可选。值的顺序是参数更新顺序。当使用参数分组功能时,通常使用该配置项保持 `parameters` 的顺序以提升性能。如果键中存在"order_params",则会忽略该组配置中的其他键。"order_params"中的参数必须在某一组 `params` 参数中。

View File

@ -3,7 +3,7 @@
.. py:class:: mindspore.ops.Broadcast(root_rank, group=GlobalComm.WORLD_COMM_GROUP)
对输入数据整广播。
对输入数据整广播。
.. note::
集合中的所有进程的Tensor的shape和数据格式相同。

View File

@ -16,5 +16,5 @@
**异常:**
- **TypeError** - `input_x` 既不是Tensor也不是Number
- **TypeError** - `type` 不是Number
- **TypeError** - `input_x` 既不是Tensor也不是数值型
- **TypeError** - `type` 不是数值型

View File

@ -22,7 +22,7 @@ mindspore.ops.LogSoftmax
**输出:**
Tensor数据类型和shape与logits相同。
Tensor数据类型和shape与 `logits` 相同。
**异常:**

View File

@ -3,7 +3,7 @@ mindspore.ops.LogUniformCandidateSampler
.. py:class:: mindspore.ops.LogUniformCandidateSampler(num_true=1, num_sampled=5, unique=True, range_max=5, seed=0)
使用log-uniform(Zipfian)分布对一组类进行采样。
使用log-uniform(Zipfian)分布对一组类进行采样。
该操作从整数范围[0, `range_max` )中随机采样一个采样类( `sampled_candidates` )的Tensor。
@ -17,13 +17,13 @@ mindspore.ops.LogUniformCandidateSampler
**输入:**
- **true_classes** (Tensor) - 目标类其数据类型为int64shape为(batch_size, num_true)。
- **true_classes** (Tensor) - 目标类其数据类型为int64shape为 :math:`(batch\_size, num\_true)`
**输出:**
3个Tensor组成的元组。
- **sampled_candidates** (Tensor) - shape为(num_sampled,)且数据类型与 `true_classes` 相同的Tensor。
- **sampled_candidates** (Tensor) - shape为 :math:`(num\_sampled,)` 且数据类型与 `true_classes` 相同的Tensor。
- **true_expected_count** (Tensor) - shape与 `true_classes` 相同且数据类型为float32的Tensor。
- **sampled_expected_count** (Tensor) - shape与 `sampled_candidates` 相同且数据类型为float32的Tensor。

View File

@ -20,8 +20,8 @@ mindspore.ops.NotEqual
**输入:**
- **x** (Union[Tensor, Number, bool]) - 第一个输入可以是Number或bool也可以是数据类型为Number或bool的Tensor。
- **y** (Union[Tensor, Number, bool]) - 第二个输入可以是Number或bool。也可以是数据类型为Number或bool的Tensor。
- **x** (Union[Tensor, Number, bool]) - 第一个输入可以是数值型或bool也可以是数据类型为数值型或bool的Tensor。
- **y** (Union[Tensor, Number, bool]) - 第二个输入可以是数值型或bool。也可以是数据类型为数值型或bool的Tensor。
**输出:**
@ -29,5 +29,5 @@ mindspore.ops.NotEqual
**异常:**
- **TypeError** - `x``y` 不是以下之一Tensor、Number、bool。
- **TypeError** - `x``y` 不是以下之一Tensor、数值型、bool。
- **TypeError** - `x``y` 都不是Tensor。

View File

@ -15,7 +15,7 @@ mindspore.ops.ReLU
**输入:**
- **input_x** (Tensor) - ReLU的输入任意维度的Tensor。其数据类型为Number
- **input_x** (Tensor) - ReLU的输入任意维度的Tensor。其数据类型为数值型
**输出:**
@ -23,5 +23,5 @@ mindspore.ops.ReLU
**异常:**
- **TypeError** - `input_x` 的数据类型不是Number
- **TypeError** - `input_x` 的数据类型不是数值型
- **TypeError** - `input_x` 不是Tensor。

View File

@ -13,7 +13,7 @@ mindspore.ops.ReduceMax
**输入:**
- **x** (Tensor[Number]) - ReduceMax的输入任意维度的Tensor秩应小于8。其数据类型为number
- **x** (Tensor[Number]) - ReduceMax的输入任意维度的Tensor秩应小于8。其数据类型为数值型
- **axis** (Union[int, tuple(int), list(int)]) - 指定计算维度。默认值:(),即计算所有元素的最大值。只允许常量值,取值范围[-rank(x), rank(x))。
**输出:**

View File

@ -3,7 +3,7 @@ mindspore.ops.ReduceMean
.. py:class:: mindspore.ops.ReduceMean(keep_dims=False)
默认情况下,输出张量各维度上的平均值,以达到对所有维度进行归约的目的。也可以对指定维度进行求平均值归约。
默认情况下,输出Tensor各维度上的平均值,以达到对所有维度进行归约的目的。也可以对指定维度进行求平均值归约。
通过指定 `keep_dims` 参数,来控制输出和输入的维度是否相同。

View File

@ -3,7 +3,7 @@ mindspore.ops.ReduceSum
.. py:class:: mindspore.ops.ReduceSum(keep_dims=False)
默认情况下,输出张量各维度上的和,以达到对所有维度进行归约的目的。也可以对指定维度进行求和归约。
默认情况下,输出Tensor各维度上的和,以达到对所有维度进行归约的目的。也可以对指定维度进行求和归约。
通过指定 `keep_dims` 参数,来控制输出和输入的维度是否相同。

View File

@ -12,7 +12,7 @@ mindspore.ops.ReverseSequence
**输入:**
- **x** (Tensor) - 输入需反转的数据其数据类型支持包括bool在内的所有Number类型。
- **x** (Tensor) - 输入需反转的数据其数据类型支持包括bool在内的所有数值型。
- **seq_lengths** (Tensor) - 指定反转长度为一维向量其数据类型为int32或int64。
**输出:**

View File

@ -14,7 +14,7 @@ mindspore.ops.ReverseV2
**输入:**
- **input_x** (Tensor) - 输入需反转的任意维度的Tensor。数据类型为Number不包括float64。
- **input_x** (Tensor) - 输入需反转的任意维度的Tensor。数据类型为数值型不包括float64。
**输出:**

View File

@ -8,7 +8,7 @@
**参数:**
- **axis** (int) - 指定排序的轴。默认值:-1。
- **descending** (bool) - 指定排序方式。如果descending为True则根据value对元素进行升序排序。默认值False。
- **descending** (bool) - 指定排序方式。如果 `descending` 为True则根据value对元素进行降序排序。默认值False。
**输入:**

View File

@ -13,7 +13,7 @@
**输入:**
- **x** (Tensor) - Sqrt的输入任意维度的Tensor其秩应小于8数据类型为Number
- **x** (Tensor) - Sqrt的输入任意维度的Tensor其秩应小于8数据类型为数值型
**输出:**

View File

@ -21,7 +21,7 @@
如果设置了 `new_ax_mask` 的第i位则忽略 `begin``end``strides` 并在输出Tensor的指定位置添加新的长度为1的维度。
对于5*6*7的Tensor `x[:2, newaxis, :6]` 将产生一个shape为(2, 1, 7)的Tensor。
对于5*6*7的Tensor `x[:2, newaxis, :6]` 将产生一个shape为 :math:`(2, 1, 7)` 的Tensor。
如果设置了 `shrink_ax_mask` 的第i位则第i个大小将维度收缩1并忽略 `begin[i]``end[i]``strides[i]` 索引处的值。
@ -43,7 +43,7 @@
- **input_x** (Tensor) - 需要切片处理的输入Tensor。
- **begin** (tuple[int]) - 指定开始切片的索引。输入为一个tuple仅支持常量值。
- **end** (tuple[int]) - 指定结束切片的索引。输入为一个tuple仅支持常量值。
- **strides** (tuple[int]) - tuple指定各维度切片的步长。仅支持常量值。
- **strides** (tuple[int]) - 指定各维度切片的步长。输入为一个tuple仅支持常量值。
**输出:**

View File

@ -5,15 +5,15 @@
将tuple转换为Tensor。
如果tuple中第一个Number的数据类型为整数则输出Tensor的数据类型为int。否则输出Tensor的数据类型为float。
如果tuple中第一个数据类型为int则输出Tensor的数据类型为int。否则输出Tensor的数据类型为float。
**输入:**
- **input_x** (tuple) - Number组成的tuple。这些Number具有相同的类型。仅支持常量值。shape为 :math:`(N,*)` ,其中 :math:`*` 表示任意数量的附加维度。
- **input_x** (tuple) - 数值型组成的tuple。其元素具有相同的类型。仅支持常量值。shape为 :math:`(N,*)` ,其中 :math:`*` 表示任意数量的附加维度。
**输出:**
Tensor。如果输入tuple包含 `N`Number则输出Tensor的shape为(N,)。
Tensor。如果输入tuple包含 `N`数值型元素则输出Tensor的shape为(N,)。
**异常:**

View File

@ -5,7 +5,7 @@
根据指定轴对输入矩阵进行分解。
在指定轴上矩阵分解的rank为 `R` 的Tensor输出rank为 `(R-1)` 的Tensor
若输入Tensor在指定的轴上的rank为 `R` 则输出Tensor的rank为 `(R-1)`
给定一个shape为 :math:`(x_1, x_2, ..., x_R)` 的Tensor。如果存在 :math:`0 \le axis` 则输出Tensor的shape为 :math:`(x_1, x_2, ..., x_{axis}, x_{axis+2}, ..., x_R)`

View File

@ -12,7 +12,7 @@ mindspore.ops.matmul
- **x1** (Tensor) - 输入Tensor不支持Scalar `x1` 的最后一维度和 `x2` 的倒数第二维度相等,且 `x1``x2` 彼此支持广播。
- **x2** (Tensor) - 输入Tensor不支持Scalar `x1` 的最后一维度和 `x2` 的倒数第二维度相等,且 `x1``x2` 彼此支持广播。
- **dtype** (:class:mindspore.dtype, optional) - 指定输入Tensor的数据类型默认None。
- **dtype** (:class:`mindspore.dtype`, optional) - 指定输入Tensor的数据类型默认None。
**返回:**

View File

@ -14,7 +14,7 @@
- **minval** (Tensor) - 指定生成随机值的最小值其数据类型为int32或float32。如果数据类型为int32则只允许输入一个数字。
- **maxval** (Tensor) - 指定生成随机值的最大值其数据类型为int32或float32。如果数据类型为int32则只允许输入一个数字。
- **seed** (int) - 指定随机种子用于随机数生成器生成伪随机数。随机数为非负数。默认值None将被视为0
- **dtype** (mindspore.dtype) - 指定输入的数据类型。如果数据类型为int32则从离散型均匀分布中生成Number如果数据类型是float32则从连续型均匀分布中生成Number。仅支持这两种数据类型。默认值mindspore.float32。
- **dtype** (mindspore.dtype) - 指定输入的数据类型。如果数据类型为int32则从离散型均匀分布中生成数值型数据如果数据类型是float32则从连续型均匀分布中生成数值型数据。仅支持这两种数据类型。默认值mindspore.float32。
**返回:**

View File

@ -392,13 +392,13 @@ class BatchNorm2d(_BatchNorm):
Note:
The implementation of BatchNorm is different in graph mode and pynative mode, therefore that mode can not be
changed after net was initialized.
Note that the formula for updating the moving_mean and moving_var is
Note that the formula for updating the :math:`moving\_mean` and :math:`moving\_var` is
.. math::
\text{moving_mean}=\text{moving_meanmomentum}+μ_β\text{(1momentum)}\\
\text{moving_var}=\text{moving_varmomentum}+σ^2\text{(1momentum)}
where :math:`moving_mean, moving_var` are the updated mean and variance,
where :math:`moving\_mean` is the updated mean, :math:`moving\_var` is the updated variance,
:math:`μ_β, σ^2` are the observed value (mean and variance) of each batch of data.
Args:
@ -1009,7 +1009,7 @@ class GroupNorm(Cell):
'he_uniform', etc. Default: 'zeros'. If beta_init is a Tensor, the shape must be [num_channels].
Inputs:
- **x** (Tensor) - The input feature with shape [N, C, H, W].
- **x** (Tensor) - The input feature with shape :math:`(N, C, H, W)` .
Outputs:
Tensor, the normalized and scaled offset tensor, has the same shape and data type as the `x`.

View File

@ -182,12 +182,12 @@ class RNNCell(RNNCellBase):
nonlinearity (str): The non-linearity to use. Can be either `tanh` or `relu`. Default: `tanh`.
Inputs:
- **x** (Tensor) - Tensor of shape (batch_size, `input_size`).
- **hx** (Tensor) - Tensor of data type mindspore.float32 and shape (batch_size, `hidden_size`).
- **x** (Tensor) - Tensor of shape :math:`(batch\_size, input\_size)` .
- **hx** (Tensor) - Tensor of data type mindspore.float32 and shape :math:`(batch\_size, hidden\_size)` .
Data type of `hx` must be the same as `x`.
Outputs:
- **hx'** (Tensor) - Tensor of shape (batch_size, `hidden_size`).
- **hx'** (Tensor) - Tensor of shape :math:`(batch\_size, hidden\_size)` .
Raises:
TypeError: If `input_size` or `hidden_size` is not an int or not greater than 0.

View File

@ -580,7 +580,7 @@ class RNN(_RNNBase):
For each element in the input sequence, each layer computes the following function:
.. math::
h_t = \tanh(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})
h_t = activation(W_{ih} x_t + b_{ih} + W_{hh} h_{(t-1)} + b_{hh})
Here :math:`h_t` is the hidden state at time `t`, :math:`x_t` is
the input at time `t`, and :math:`h_{(t-1)}` is the hidden state of the
@ -601,22 +601,22 @@ class RNN(_RNNBase):
Inputs:
- **x** (Tensor) - Tensor of data type mindspore.float32 or mindspore.float16 and
shape (seq_len, batch_size, `input_size`) or (batch_size, seq_len, `input_size`).
shape :math:`(seq\_len, batch\_size, input\_size)` or :math:`(batch\_size, seq\_len, input\_size)` .
- **hx** (Tensor) - Tensor of data type mindspore.float32 or mindspore.float16 and
shape (num_directions * `num_layers`, batch_size, `hidden_size`). The data type of `hx` must be the same as
`x`.
shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)` .
The data type of `hx` must be the same as `x`.
- **seq_length** (Tensor) - The length of each sequence in an input batch.
Tensor of shape :math:`(\text{batch_size})`. Default: None.
Tensor of shape :math:`(batch\_size)` . Default: None.
This input indicates the real sequence length before padding to avoid padded elements
have been used to compute hidden state and affect the final output. It is recommended to
use this input when **x** has padding elements.
use this input when `x` has padding elements.
Outputs:
Tuple, a tuple contains (`output`, `hx_n`).
- **output** (Tensor) - Tensor of shape (seq_len, batch_size, num_directions * `hidden_size`) or
(batch_size, seq_len, num_directions * `hidden_size`).
- **hx_n** (Tensor) - Tensor of shape (num_directions * `num_layers`, batch_size, `hidden_size`).
- **output** (Tensor) - Tensor of shape :math:`(seq\_len, batch\_size, num\_directions * hidden\_size)` or
:math:`(batch\_size, seq\_len, num\_directions * hidden\_size)` .
- **hx_n** (Tensor) - Tensor of shape :math:`(num\_directions * num\_layers, batch\_size, hidden\_size)` .
Raises:
TypeError: If `input_size`, `hidden_size` or `num_layers` is not an int.

View File

@ -114,6 +114,9 @@ class LossBase(Cell):
and must be broadcastable to inputs (i.e., all dimensions must be either `1`,
or the same as the corresponding inputs dimension). Default: 1.0.
Returns:
Return the weighted loss.
Examples:
>>> class Net(nn.LossBase):
... def __init__(self, reduction='mean'):
@ -1080,8 +1083,8 @@ class BCELoss(LossBase):
- **labels** (Tensor) - The label tensor with shape :math:`(N, *)`, the same shape and data type as `logits`.
Outputs:
Tensor or Scalar, if `reduction` is 'none', then output is a tensor and has the same shape as `logits`.
Otherwise, the output is a scalar.
Tensor, has the same dtype as `logits`. if `reduction` is 'none', then it has the same shape as `logits`.
Otherwise, it is a scalar Tensor.
Raises:
TypeError: If dtype of `logits`, `labels` or `weight` (if given) is neither float16 not float32.

View File

@ -3390,7 +3390,7 @@ class StridedSlice(PrimitiveWithInfer):
If the ith bit of `new_axis_mask` is set, `begin`, `end` and `strides` are ignored and a new length 1
dimension is added at the specified position in tthe output tensor.
As for a 5*6*7 tensor, `x[:2, newaxis, :6]` will produce a tensor with shape (2, 1, 7).
As for a 5*6*7 tensor, `x[:2, newaxis, :6]` will produce a tensor with shape :math:`(2, 1, 7)` .
If the ith bit of `shrink_axis_mask` is set, ith size shrinks the dimension by 1, taking on the value
at index `begin[i]`, `end[i]` and `strides[i]` are ignored.

View File

@ -676,7 +676,7 @@ class UniformCandidateSampler(PrimitiveWithInfer):
class LogUniformCandidateSampler(PrimitiveWithInfer):
"""
r"""
Generates random labels with a log-uniform distribution for sampled_candidates.
Randomly samples a tensor of sampled classes from the range of integers [0, range_max).
@ -691,12 +691,14 @@ class LogUniformCandidateSampler(PrimitiveWithInfer):
seed (int): Random seed, must be non-negative. Default: 0.
Inputs:
- **true_classes** (Tensor) - The target classes. With data type of int64 and shape [batch_size, num_true].
- **true_classes** (Tensor) - The target classes. With data type of int64 and
shape :math:`(batch\_size, num\_true)` .
Outputs:
Tuple of 3 Tensors.
- **sampled_candidates** (Tensor) - A Tensor with shape (num_sampled,) and the same type as `true_classes`.
- **sampled_candidates** (Tensor) - A Tensor with shape :math:`(num\_sampled,)` and
the same type as `true_classes`.
- **true_expected_count** (Tensor) - A Tensor with the same shape as `true_classes and` type float32.
- **sampled_expected_count** (Tensor) - A Tensor with the same shape as `sampled_candidates` and type float32.