Browse Source

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

Merge pull request !32448 from zhangfanghe/code_docs_zfh_master_401
pull/1/head
i-robot Gitee 4 years ago
parent
commit
f07a608ffa
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 85 additions and 76 deletions
  1. +1
    -1
      docs/api/api_python/nn/mindspore.nn.BCELoss.rst
  2. +2
    -2
      docs/api/api_python/nn/mindspore.nn.BatchNorm2d.rst
  3. +1
    -1
      docs/api/api_python/nn/mindspore.nn.DiceLoss.rst
  4. +1
    -1
      docs/api/api_python/nn/mindspore.nn.Dropout.rst
  5. +2
    -2
      docs/api/api_python/nn/mindspore.nn.Embedding.rst
  6. +2
    -2
      docs/api/api_python/nn/mindspore.nn.EmbeddingLookup.rst
  7. +1
    -1
      docs/api/api_python/nn/mindspore.nn.FocalLoss.rst
  8. +4
    -4
      docs/api/api_python/nn/mindspore.nn.GroupNorm.rst
  9. +5
    -1
      docs/api/api_python/nn/mindspore.nn.LossBase.rst
  10. +6
    -6
      docs/api/api_python/nn/mindspore.nn.RNN.rst
  11. +4
    -4
      docs/api/api_python/nn/mindspore.nn.RNNCell.rst
  12. +1
    -1
      docs/api/api_python/nn/mindspore.nn.Triu.rst
  13. +1
    -1
      docs/api/api_python/nn/mindspore.nn.optim_group_lr.rst
  14. +1
    -1
      docs/api/api_python/nn/mindspore.nn.optim_group_order.rst
  15. +1
    -1
      docs/api/api_python/ops/mindspore.ops.Broadcast.rst
  16. +2
    -2
      docs/api/api_python/ops/mindspore.ops.Cast.rst
  17. +1
    -1
      docs/api/api_python/ops/mindspore.ops.LogSoftmax.rst
  18. +3
    -3
      docs/api/api_python/ops/mindspore.ops.LogUniformCandidateSampler.rst
  19. +3
    -3
      docs/api/api_python/ops/mindspore.ops.NotEqual.rst
  20. +2
    -2
      docs/api/api_python/ops/mindspore.ops.ReLU.rst
  21. +1
    -1
      docs/api/api_python/ops/mindspore.ops.ReduceMax.rst
  22. +1
    -1
      docs/api/api_python/ops/mindspore.ops.ReduceMean.rst
  23. +1
    -1
      docs/api/api_python/ops/mindspore.ops.ReduceSum.rst
  24. +1
    -1
      docs/api/api_python/ops/mindspore.ops.ReverseSequence.rst
  25. +1
    -1
      docs/api/api_python/ops/mindspore.ops.ReverseV2.rst
  26. +1
    -1
      docs/api/api_python/ops/mindspore.ops.Sort.rst
  27. +1
    -1
      docs/api/api_python/ops/mindspore.ops.Sqrt.rst
  28. +2
    -2
      docs/api/api_python/ops/mindspore.ops.StridedSlice.rst
  29. +3
    -3
      docs/api/api_python/ops/mindspore.ops.TupleToArray.rst
  30. +1
    -1
      docs/api/api_python/ops/mindspore.ops.Unstack.rst
  31. +1
    -1
      docs/api/api_python/ops/mindspore.ops.func_matmul.rst
  32. +1
    -1
      docs/api/api_python/ops/mindspore.ops.func_uniform.rst
  33. +3
    -3
      mindspore/python/mindspore/nn/layer/normalization.py
  34. +3
    -3
      mindspore/python/mindspore/nn/layer/rnn_cells.py
  35. +9
    -9
      mindspore/python/mindspore/nn/layer/rnns.py
  36. +5
    -2
      mindspore/python/mindspore/nn/loss/loss.py
  37. +1
    -1
      mindspore/python/mindspore/ops/operations/array_ops.py
  38. +5
    -3
      mindspore/python/mindspore/ops/operations/random_ops.py

+ 1
- 1
docs/api/api_python/nn/mindspore.nn.BCELoss.rst View File

@@ -37,7 +37,7 @@ mindspore.nn.BCELoss

**输出:**

Tensor或Scalar,如果 `reduction` 为'None',则输出是Tensor,其shape与 `logits` 相同。否则,输出为Scalar。
Tensor,数据类型与 `logits` 相同。如果 `reduction` 为'none',则shape与 `logits` 相同。否则,输出为Scalar的Tensor。

**异常:**



+ 2
- 2
docs/api/api_python/nn/mindspore.nn.BatchNorm2d.rst 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{*(1−momentum)}\\
\text{moving_var}=\text{moving_var*momentum}+σ^2_β\text{*(1−momentum)}

其中, :math:`moving_mean, moving_var` 分别是更新后的均值和方差, :math:`μ_β, σ^2_β` 是每一批的数据的观测值(均值和方差)。
其中, :math:`moving\_mean` 是更新后的均值, :math:`moving\_var` 是更新后的方差, :math:`μ_β, σ^2_β` 是每一批的数据的观测值(均值和方差)。

**参数:**



+ 1
- 1
docs/api/api_python/nn/mindspore.nn.DiceLoss.rst View File

@@ -24,7 +24,7 @@ mindspore.nn.DiceLoss

**输出:**

Tensor,shape为每样本采样的Dice loss的Tensor。
Tensor,shape为每样本采样的Dice系数的Tensor。

**异常:**



+ 1
- 1
docs/api/api_python/nn/mindspore.nn.Dropout.rst 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::
每个通道将在每次构造调用时独立归零
训练过程中每步对同一通道(或神经元)独立进行丢弃

**参数:**



+ 2
- 2
docs/api/api_python/nn/mindspore.nn.Embedding.rst 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。该功能已停用。



+ 2
- 2
docs/api/api_python/nn/mindspore.nn.EmbeddingLookup.rst 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

**输出:**

Tensor,shape为 :math:`(z_1, z_2, ..., z_N)` 的tensor。
Tensor,shape为 :math:`(z_1, z_2, ..., z_N)` 的Tensor。

**异常:**



+ 1
- 1
docs/api/api_python/nn/mindspore.nn.FocalLoss.rst 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>`_ 中提出提高了图像目标检测的效果。

函数如下:



+ 4
- 4
docs/api/api_python/nn/mindspore.nn.GroupNorm.rst 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。

+ 5
- 1
docs/api/api_python/nn/mindspore.nn.LossBase.rst 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。

**返回:**

返回加权损失。

+ 6
- 6
docs/api/api_python/nn/mindspore.nn.RNN.rst 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` 。

@@ -25,16 +25,16 @@ mindspore.nn.RNN

**输入:**
- **x** (Tensor) - 数据类型为mindspore.float32或mindspore.float16,shape为(seq_len, batch_size, `input_size`)或(batch_size, seq_len, `input_size`)的Tensor。
- **hx** (Tensor) - 数据类型为mindspore.float32或mindspore.float16,shape为(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.float16,shape为 :math:`(seq\_len, batch\_size, input\_size)` 或 :math:`(batch\_size, seq\_len, input\_size)` 的Tensor。
- **hx** (Tensor) - 数据类型为mindspore.float32或mindspore.float16,shape为 :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。

**异常:**



+ 4
- 4
docs/api/api_python/nn/mindspore.nn.RNNCell.rst 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})
@@ -21,12 +21,12 @@ mindspore.nn.RNNCell

**输入:**
- **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。

**异常:**


+ 1
- 1
docs/api/api_python/nn/mindspore.nn.Triu.rst View File

@@ -12,7 +12,7 @@ mindspore.nn.Triu

**输入:**

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

**输出:**


+ 1
- 1
docs/api/api_python/nn/mindspore.nn.optim_group_lr.rst View File

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

+ 1
- 1
docs/api/api_python/nn/mindspore.nn.optim_group_order.rst View File

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

+ 1
- 1
docs/api/api_python/ops/mindspore.ops.Broadcast.rst View File

@@ -3,7 +3,7 @@

.. py:class:: mindspore.ops.Broadcast(root_rank, group=GlobalComm.WORLD_COMM_GROUP)

对输入数据整广播。
对输入数据整广播。

.. note::
集合中的所有进程的Tensor的shape和数据格式相同。


+ 2
- 2
docs/api/api_python/ops/mindspore.ops.Cast.rst View File

@@ -16,5 +16,5 @@

**异常:**
- **TypeError** - `input_x` 既不是Tensor也不是Number
- **TypeError** - `type` 不是Number
- **TypeError** - `input_x` 既不是Tensor也不是数值型
- **TypeError** - `type` 不是数值型

+ 1
- 1
docs/api/api_python/ops/mindspore.ops.LogSoftmax.rst View File

@@ -22,7 +22,7 @@ mindspore.ops.LogSoftmax

**输出:**

Tensor,数据类型和shape与logits相同。
Tensor,数据类型和shape与 `logits` 相同。

**异常:**



+ 3
- 3
docs/api/api_python/ops/mindspore.ops.LogUniformCandidateSampler.rst 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) - 目标类,其数据类型为int64,shape为(batch_size, num_true)。
- **true_classes** (Tensor) - 目标类,其数据类型为int64,shape为 :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。



+ 3
- 3
docs/api/api_python/ops/mindspore.ops.NotEqual.rst 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。

+ 2
- 2
docs/api/api_python/ops/mindspore.ops.ReLU.rst 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。

+ 1
- 1
docs/api/api_python/ops/mindspore.ops.ReduceMax.rst 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))。

**输出:**


+ 1
- 1
docs/api/api_python/ops/mindspore.ops.ReduceMean.rst View File

@@ -3,7 +3,7 @@ mindspore.ops.ReduceMean

.. py:class:: mindspore.ops.ReduceMean(keep_dims=False)

默认情况下,输出张量各维度上的平均值,以达到对所有维度进行归约的目的。也可以对指定维度进行求平均值归约。
默认情况下,输出Tensor各维度上的平均值,以达到对所有维度进行归约的目的。也可以对指定维度进行求平均值归约。

通过指定 `keep_dims` 参数,来控制输出和输入的维度是否相同。



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.ReduceSum.rst View File

@@ -3,7 +3,7 @@ mindspore.ops.ReduceSum

.. py:class:: mindspore.ops.ReduceSum(keep_dims=False)

默认情况下,输出张量各维度上的和,以达到对所有维度进行归约的目的。也可以对指定维度进行求和归约。
默认情况下,输出Tensor各维度上的和,以达到对所有维度进行归约的目的。也可以对指定维度进行求和归约。

通过指定 `keep_dims` 参数,来控制输出和输入的维度是否相同。



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.ReverseSequence.rst View File

@@ -12,7 +12,7 @@ mindspore.ops.ReverseSequence

**输入:**

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

**输出:**


+ 1
- 1
docs/api/api_python/ops/mindspore.ops.ReverseV2.rst View File

@@ -14,7 +14,7 @@ mindspore.ops.ReverseV2

**输入:**

- **input_x** (Tensor) - 输入需反转的任意维度的Tensor。数据类型为Number,不包括float64。
- **input_x** (Tensor) - 输入需反转的任意维度的Tensor。数据类型为数值型,不包括float64。

**输出:**



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.Sort.rst View File

@@ -8,7 +8,7 @@
**参数:**

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

**输入:**



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.Sqrt.rst View File

@@ -13,7 +13,7 @@

**输入:**

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

**输出:**



+ 2
- 2
docs/api/api_python/ops/mindspore.ops.StridedSlice.rst 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,仅支持常量值。

**输出:**



+ 3
- 3
docs/api/api_python/ops/mindspore.ops.TupleToArray.rst 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,)。

**异常:**



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.Unstack.rst 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)` 。



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.func_matmul.rst 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。

**返回:**



+ 1
- 1
docs/api/api_python/ops/mindspore.ops.func_uniform.rst 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。

**返回:**



+ 3
- 3
mindspore/python/mindspore/nn/layer/normalization.py 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_mean∗momentum}+μ_β\text{∗(1−momentum)}\\
\text{moving_var}=\text{moving_var∗momentum}+σ^2_β\text{∗(1−momentum)}

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`.


+ 3
- 3
mindspore/python/mindspore/nn/layer/rnn_cells.py 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.


+ 9
- 9
mindspore/python/mindspore/nn/layer/rnns.py 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.


+ 5
- 2
mindspore/python/mindspore/nn/loss/loss.py 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.


+ 1
- 1
mindspore/python/mindspore/ops/operations/array_ops.py View File

@@ -3363,7 +3363,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.


+ 5
- 3
mindspore/python/mindspore/ops/operations/random_ops.py View File

@@ -727,7 +727,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).
@@ -742,12 +742,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.



Loading…
Cancel
Save