mindspore.train.Top5CategoricalAccuracy

查看源文件
class mindspore.train.Top5CategoricalAccuracy[源代码]

计算top-5分类正确率。此类是TopKCategoricalAccuracy的特殊类。有关更多详细信息,请参阅 mindspore.train.TopKCategoricalAccuracy

支持平台:

Ascend GPU CPU

样例:

>>> import numpy as np
>>> import mindspore
>>> from mindspore import Tensor
>>> from mindspore.train import Top5CategoricalAccuracy
>>>
>>> x = Tensor(np.array([[0.2, 0.5, 0.3, 0.6, 0.2], [0.1, 0.35, 0.5, 0.2, 0.],
...            [0.9, 0.6, 0.2, 0.01, 0.3]]), mindspore.float32)
>>> y = Tensor(np.array([2, 0, 1]), mindspore.float32)
>>> topk = Top5CategoricalAccuracy()
>>> topk.clear()
>>> topk.update(x, y)
>>> output = topk.eval()
>>> print(output)
1.0