Classification#

kornia.metrics.accuracy(pred, target, topk=(1,))[source]#

Compute the accuracy over the k top predictions for the specified values of k.

Parameters:
  • pred (Tensor) – the input torch.Tensor with the logits to evaluate.

  • target (Tensor) – the torch.Tensor containing the ground truth.

  • topk (Tuple[int, ...], optional) – the expected topk ranking. Default: (1,)

Return type:

List[Tensor]

Example

>>> logits = torch.tensor([[0, 1, 0]])
>>> target = torch.tensor([[1]])
>>> accuracy(logits, target)
[tensor(100.)]