mindspore/docs/api/api_python/nn/mindspore.nn.MarginRankingL...

33 lines
1.7 KiB
ReStructuredText
Raw Normal View History

2022-10-14 15:26:42 +08:00
mindspore.nn.MarginRankingLoss
===============================
.. py:class:: mindspore.nn.MarginRankingLoss(margin=0.0, reduction='mean')
排序损失函数,用于创建一个衡量给定损失的标准。
给定两个Tensor :math:`x1`:math:`x2` 以及一个Tensor标签 :math:`y` 值为1或-1公式如下
.. math::
\text{loss}(x1, x2, y) = \max(0, -y * (x1 - x2) + \text{margin})
参数:
- **margin** (float) - 指定运算的调节因子。默认值0.0。
- **reduction** (str) - 指定输出结果的计算方式。可选值为"none"、"mean"或"sum",分别表示不指定计算方式、使用均值计算和使用求和计算。默认值:"mean"。
输入:
- **input1** (Tensor) - 输入Tensorshape :math:`(N,*)` ,其中 `*` 代表任意数量的附加维度。
- **input2** (Tensor) - 输入Tensorshape :math:`(N,*)` 。shape和数据类型与 `input1` 相同。
- **target** (Tensor) - 输入值为1或-1。假设 `input1` 的shape是 :math:`(x_1, x_2, x_3, ..., x_R)` ,那么 `labels` 的shape必须是 :math:`(x_1, x_3, x_4, ..., x_R)`
输出:
Tensor或Scalar如果 `reduction` 为"none"其shape与 `labels` 相同。否则将返回为Scalar。
异常:
- **TypeError** - `margin` 不是float。
- **TypeError** - `input1` `input2``target` 不是Tensor。
- **TypeError** - `input1``input2` 类型不一致。
- **TypeError** - `input1``target` 类型不一致。
- **ValueError** - `input1``input2` shape不一致。
- **ValueError** - `input1``target` shape不一致。
- **ValueError** - `reduction` 不为"none""mean"或"sum"。