megengine.functional.nn.topk_accuracy

topk_accuracy(logits, target, topk=1)[源代码]

Calculates the classification accuracy given predicted logits and ground-truth labels.

参数
  • logits (Tensor) – model predictions of shape [batch_size, num_classes], representing the probability (likelyhood) of each class.

  • target (Tensor) – ground-truth labels, 1d tensor of int32.

  • topk (Union[int, Iterable[int]]) – specifies the topk values, could be an int or tuple of ints. Default: 1

返回类型

Union[Tensor, Iterable[Tensor]]

返回

tensor(s) of classification accuracy between 0.0 and 1.0.