Classification#
- kornia.metrics.accuracy(pred, target, topk=(1,))[source]#
Compute the accuracy over the k top predictions for the specified values of k.
- Convention:
predholds one score per class, \((B, C)\); only the order of the scores in a row matters.targetholds class indices, \((B,)\) or \((B, 1)\).The result is a list with one 0-d float32 tensor per entry of
topk, in that order. Each is a percentage in \([0, 100]\), not a fraction, taken over the whole batch: a sample counts forkwhen its target is among itskhighest scores, and akabove \(C\) counts as \(C\). Losses and metrics lists the scale of every task metric.
- Parameters:
- Return type:
Example
>>> logits = torch.tensor([[0, 1, 0]]) >>> target = torch.tensor([[1]]) >>> accuracy(logits, target) [tensor(100.)]