mindspore/docs/api/api_python/nn/mindspore.nn.MSELoss.rst

41 lines
1.9 KiB
ReStructuredText
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

mindspore.nn.MSELoss
=============================
.. py:class:: mindspore.nn.MSELoss(reduction='mean')
用于计算预测值与标签值之间的均方误差。
假设 :math:`x`:math:`y` 为一维Tensor长度 :math:`N` ,则计算 :math:`x`:math:`y` 的unreduced loss即reduction参数设置为 ``'none'``)的公式如下:
.. math::
\ell(x, y) = L = \{l_1,\dots,l_N\}^\top, \quad \text{with} \quad l_n = (x_n - y_n)^2.
其中, :math:`N` 为batch size。如果 `reduction` 不是 ``'none'`` ,则:
.. math::
\ell(x, y) =
\begin{cases}
\operatorname{mean}(L), & \text{if reduction} = \text{'mean';}\\
\operatorname{sum}(L), & \text{if reduction} = \text{'sum'.}
\end{cases}
参数:
- **reduction** (str可选) - 指定应用于输出结果的规约计算方式,可选 ``'mean'````'sum'````'none'`` ,默认值: ``'mean'``
- ``'none'``:不应用规约方法。
- ``'mean'``:计算输出元素的平均值。
- ``'sum'``:计算输出元素的总和。
输入:
- **logits** (Tensor) - 输入预测值任意维度的Tensor。
- **labels** (Tensor) - 输入标签任意维度的Tensor。支持在 `logits``labels` shape不相同的情况下通过广播保持一致。
输出:
- Tensor如果 `reduction```'mean'````'sum'``输出的shape为 `Tensor Scalar`
- 如果 `reduction```'none'`` 输出的shape则是 `logits``labels` 广播之后的shape。
异常:
- **ValueError** - 如果 `reduction` 不为 ``'mean'`` ``'sum'````'none'`` 中的一个。
- **ValueError** - 如果 `logits``labels` 的shape不同且不能广播。
- **TypeError** - 如果 `logits``labels` 数据类型不一致。