megengine.functional.topk_accuracy

topk_accuracy(logits, target, topk=1)[source]

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

Parameters
  • 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

Return type

Union[Tensor, Iterable[Tensor]]

Returns

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