mindspore.nn.Metric

class mindspore.nn.Metric[source]

Base class of metric.

Note

For examples of subclasses, please refer to the definition of class MAE, Recall etc.

abstract clear()[source]

An interface describes the behavior of clearing the internal evaluation result.

Note

All subclasses must override this interface.

abstract eval()[source]

An interface describes the behavior of computing the evaluation result.

Note

All subclasses must override this interface.

property indexes

The _indexes is a private attribute, and you can retrieve it by self.indexes.

set_indexes(indexes)[source]

The _indexes is a private attribute and you can modify it by this function. This allows you to determine the order of logits and labels to be calculated in the inputs, specially when you call the method update within this metrics.

Note

It has been applied in subclass of Metric, eg. Accuracy, BleuScore, ConfusionMatrix, CosineSimilarity, MAE, and MSE.

Parameters

indexes (List(int)) – The order of logits and labels to be rearranged.

Outputs:

Metric, its original Class instance.

Examples

>>> import numpy as np
>>> from mindspore import nn, Tensor
>>>
>>> x = Tensor(np.array([[0.2, 0.5], [0.3, 0.1], [0.9, 0.6]]))
>>> y = Tensor(np.array([1, 0, 1]))
>>> y2 = Tensor(np.array([0, 0, 1]))
>>> metric = nn.Accuracy('classification').set_indexes([0, 2])
>>> metric.clear()
>>> metric.update(x, y, y2)
>>> accuracy = metric.eval()
>>> print(accuracy)
0.3333333333333333
abstract update(*inputs)[source]

An interface describes the behavior of updating the internal evaluation result.

Note

All subclasses must override this interface.

Parameters

inputs – A variable-length input argument list.