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

65 lines
2.0 KiB
ReStructuredText
Raw Normal View History

2021-12-04 09:42:36 +08:00
mindspore.nn.Metric
====================
.. py:class:: mindspore.nn.Metric
用于计算评估指标的基类。
在计算评估指标时需要调用 `clear``update``eval` 三个方法,在继承该类自定义评估指标时,也需要实现这三个方法。其中,`update` 用于计算中间过程的内部结果,`eval` 用于计算最终评估结果,`clear` 用于重置中间结果。
请勿直接使用该类,需使用子类如 :class:`mindspore.nn.MAE`:class:`mindspore.nn.Recall` 等。
.. py:method:: clear()
2021-12-04 20:36:47 +08:00
:abstractmethod:
2021-12-04 09:42:36 +08:00
2021-12-31 16:45:06 +08:00
清除内部评估结果。
2021-12-04 09:42:36 +08:00
.. note::
所有子类都必须重写此接口。
.. py:method:: eval()
2021-12-04 20:36:47 +08:00
:abstractmethod:
2021-12-04 09:42:36 +08:00
2021-12-31 16:45:06 +08:00
计算最终评估结果。
2021-12-04 09:42:36 +08:00
.. note::
所有子类都必须重写此接口。
2021-12-04 20:36:47 +08:00
2021-12-04 09:42:36 +08:00
.. py:method:: indexes
:property:
2021-12-31 16:45:06 +08:00
获取当前的 `indexes` 值。默认为None调用 `set_indexes` 方法可修改 `indexes` 值。
2021-12-04 09:42:36 +08:00
.. py:method:: set_indexes(indexes)
该接口用于重排 `update` 的输入。
给定(label0, label1, logits)作为 `update` 的输入,将 `indexes` 设置为[2, 1],则最终使用(logits, label1)作为 `update` 的真实输入。
.. note::
在继承该类自定义评估函数时,需要用装饰器 `mindspore.nn.rearrange_inputs` 修饰 `update` 方法,否则配置的 `indexes` 值不生效。
2021-12-04 20:36:47 +08:00
2021-12-04 09:42:36 +08:00
**参数:**
2021-12-04 20:36:47 +08:00
- **indexes** (List(int)) - logits和标签的目标顺序。
2021-12-04 09:42:36 +08:00
**输出:**
:class:`Metric` ,类实例本身。
2021-12-31 16:45:06 +08:00
**异常:**
- **ValueError** - 如果输入的index类型不是list或其元素类型不全为int。
2021-12-04 09:42:36 +08:00
.. py:method:: update(*inputs)
2021-12-04 20:36:47 +08:00
:abstractmethod:
2021-12-04 09:42:36 +08:00
2021-12-31 16:45:06 +08:00
更新内部评估结果。
2021-12-04 09:42:36 +08:00
.. note::
所有子类都必须重写此接口。
**参数:**
2021-12-31 16:45:06 +08:00
- **inputs** - 可变长度输入参数列表。通常是预测值和对应的真实标签。