MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / accuracy

Function accuracy

util/misc.py:592–607  ·  view source on GitHub ↗

Computes the precision@k for the specified values of k.

(output, target, topk=(1, ))

Source from the content-addressed store, hash-verified

590
591@torch.no_grad()
592def accuracy(output, target, topk=(1, )):
593 """Computes the precision@k for the specified values of k."""
594 if target.numel() == 0:
595 return [torch.zeros([], device=output.device)]
596 maxk = max(topk)
597 batch_size = target.size(0)
598
599 _, pred = output.topk(maxk, 1, True, True)
600 pred = pred.t()
601 correct = pred.eq(target.view(1, -1).expand_as(pred))
602
603 res = []
604 for k in topk:
605 correct_k = correct[:k].view(-1).float().sum(0)
606 res.append(correct_k.mul_(100.0 / batch_size))
607 return res
608
609
610def interpolate(input,

Callers 2

loss_labelsMethod · 0.90
loss_labelsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected