MCPcopy Create free account
hub / github.com/Sense-GVT/DeCLIP / accuracy

Function accuracy

prototype/utils/misc.py:415–428  ·  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

413
414
415def accuracy(output, target, topk=(1,)):
416 """Computes the precision@k for the specified values of k"""
417 maxk = max(topk)
418 batch_size = target.size(0)
419
420 _, pred = output.topk(maxk, 1, True, True)
421 pred = pred.t()
422 correct = pred.eq(target.view(1, -1).expand_as(pred))
423
424 res = []
425 for k in topk:
426 correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
427 res.append(correct_k.mul_(100.0 / batch_size))
428 return res
429
430
431def detailed_metrics(output, target):

Callers 5

trainMethod · 0.90
trainMethod · 0.90
trainMethod · 0.90
trainMethod · 0.90
trainMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected