2021-12-04 13:55:42 +08:00
|
|
|
|
mindspore.nn.Loss
|
|
|
|
|
|
=================
|
|
|
|
|
|
|
|
|
|
|
|
.. py:class:: mindspore.nn.Loss
|
|
|
|
|
|
|
2021-12-31 16:45:06 +08:00
|
|
|
|
计算loss的平均值。如果每 :math:`n` 次迭代调用一次 `update` 方法,则计算结果为:
|
2021-12-04 13:55:42 +08:00
|
|
|
|
|
|
|
|
|
|
.. math::
|
|
|
|
|
|
loss = \frac{\sum_{k=1}^{n}loss_k}{n}
|
|
|
|
|
|
|
|
|
|
|
|
.. py:method:: clear()
|
|
|
|
|
|
|
|
|
|
|
|
内部评估结果清零。
|
|
|
|
|
|
|
|
|
|
|
|
.. py:method:: eval()
|
|
|
|
|
|
|
|
|
|
|
|
计算loss的平均值。
|
|
|
|
|
|
|
|
|
|
|
|
**返回:**
|
2021-12-04 20:36:47 +08:00
|
|
|
|
|
2021-12-04 13:55:42 +08:00
|
|
|
|
Float,loss的平均值。
|
|
|
|
|
|
|
2021-12-04 18:37:47 +08:00
|
|
|
|
**异常:**
|
|
|
|
|
|
|
2022-02-25 17:26:18 +08:00
|
|
|
|
- **RuntimeError** - 样本总数为0。
|
2021-12-04 13:55:42 +08:00
|
|
|
|
|
|
|
|
|
|
.. py:method:: update(*inputs)
|
|
|
|
|
|
|
|
|
|
|
|
更新内部评估结果。
|
|
|
|
|
|
|
2021-12-04 18:37:47 +08:00
|
|
|
|
**参数:**
|
|
|
|
|
|
|
2021-12-04 20:36:47 +08:00
|
|
|
|
- **inputs** - 输入只包含一个元素,且该元素为loss。loss的维度必须为0或1。
|
2021-12-04 18:37:47 +08:00
|
|
|
|
|
|
|
|
|
|
**异常:**
|
2021-12-04 13:55:42 +08:00
|
|
|
|
|
2021-12-04 20:36:47 +08:00
|
|
|
|
- **ValueError** - `inputs` 的长度不为1。
|
|
|
|
|
|
- **ValueError** - `inputs` 的维度不为0或1。
|