mindspore/docs/api/api_python/nn/mindspore.nn.MultiLabelSoft...

29 lines
1.2 KiB
ReStructuredText
Raw Normal View History

2022-12-28 15:10:05 +08:00
mindspore.nn.MultiLabelSoftMarginLoss
======================================
.. py:class:: mindspore.nn.MultiLabelSoftMarginLoss(weight=None, reduction='mean')
基于最大熵计算用于多标签优化的损失。计算公式如下。
.. math::
\mathcal{L}_{D} = - \frac{1}{|D|}\sum_{i = 0}^{|D|}\left(
y_{i}\ln\frac{1}{1 + e^{- x_{i}}} + \left( 1 - y_{i}
\right)\ln\frac{1}{1 + e^{x_{i}}} \right)
:math:`\mathcal{L}_{D}` 为损失值,:math:`y_{i}``target` ,
:math:`x_{i}``x` 。如果 `weight` 不为None将会和每个分类的loss相乘。
参数:
- **weight** (Union[Tensor, int, float]) - 每个类别的缩放权重。默认值None。
- **reduction** (str) - 指定应用于输出结果的计算方式。取值为"mean""sum",或"none"。默认值:"mean"。
输入:
- **x** (Tensor) - shape为(N, C)的TensorN为batch sizeC为类别个数。
- **target** (Tensor) - 目标值数据类型和shape与 `x` 的相同。
输出:
Tensor数据类型和 `x` 相同。如果 `reduction` 为"none"其shape为(N)。否则其shape为0。
异常:
2022-12-30 10:58:38 +08:00
- **ValueError** - `x``target` 的维度不等于2。