Browse Source

feat(mge): rename accuracy -> topk_accuracy

GitOrigin-RevId: b6ae007231
release-1.1
Megvii Engine Team 4 years ago
parent
commit
480375fbe3
2 changed files with 8 additions and 3 deletions
  1. +1
    -1
      imperative/python/megengine/functional/__init__.py
  2. +7
    -2
      imperative/python/megengine/functional/utils.py

+ 1
- 1
imperative/python/megengine/functional/__init__.py View File

@@ -13,7 +13,7 @@ from .math import *
from .nn import *
from .quantized import conv_bias_activation
from .tensor import *
from .utils import accuracy, copy
from .utils import *

from . import distributed # isort:skip



+ 7
- 2
imperative/python/megengine/functional/utils.py View File

@@ -18,8 +18,13 @@ from ..core.tensor.core import apply
from .math import topk as _topk
from .tensor import broadcast_to, transpose

__all__ = [
"topk_accuracy",
"copy",
]

def accuracy(

def topk_accuracy(
logits: Tensor, target: Tensor, topk: Union[int, Iterable[int]] = 1
) -> Union[Tensor, Iterable[Tensor]]:
r"""
@@ -41,7 +46,7 @@ def accuracy(

logits = tensor(np.arange(80, dtype=np.int32).reshape(8,10))
target = tensor(np.arange(8, dtype=np.int32))
top1, top5 = F.accuracy(logits, target, (1, 5))
top1, top5 = F.topk_accuracy(logits, target, (1, 5))
print(top1.numpy(), top5.numpy())

Outputs:


Loading…
Cancel
Save