MCPcopy Create free account
hub / github.com/IDEA-Research/DINO / accuracy

Function accuracy

util/misc.py:522–537  ·  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

520
521@torch.no_grad()
522def accuracy(output, target, topk=(1,)):
523 """Computes the precision@k for the specified values of k"""
524 if target.numel() == 0:
525 return [torch.zeros([], device=output.device)]
526 maxk = max(topk)
527 batch_size = target.size(0)
528
529 _, pred = output.topk(maxk, 1, True, True)
530 pred = pred.t()
531 correct = pred.eq(target.view(1, -1).expand_as(pred))
532
533 res = []
534 for k in topk:
535 correct_k = correct[:k].view(-1).float().sum(0)
536 res.append(correct_k.mul_(100.0 / batch_size))
537 return res
538
539
540def interpolate(input, size=None, scale_factor=None, mode="nearest", align_corners=None):

Callers 1

loss_labelsMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected