MCPcopy Index your code
hub / github.com/OpenGVLab/HumanBench / accuracy

Function accuracy

PATH/core/utils.py:87–100  ·  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

85
86
87def accuracy(output, target, topk=(1,)):
88 """Computes the precision@k for the specified values of k"""
89 maxk = max(topk)
90 batch_size = target.size(0)
91
92 _, pred = output.topk(maxk, 1, True, True)
93 pred = pred.t()
94 correct = pred.eq(target.reshape(1, -1).expand_as(pred))
95
96 res = []
97 for k in topk:
98 correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
99 res.append(correct_k.mul_(100.0 / batch_size))
100 return res
101
102def accuracy_multi(output, target):
103 pred = (output > 0).float()

Callers 3

forwardMethod · 0.90
forwardMethod · 0.90
forwardMethod · 0.90

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected