MCPcopy Create free account
hub / github.com/Walter0807/MotionBERT / accuracy

Function accuracy

lib/utils/learning.py:25–37  ·  view source on GitHub ↗

Computes the accuracy over the k top predictions for the specified values of k

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

Source from the content-addressed store, hash-verified

23 self.avg = self.sum / self.count
24
25def accuracy(output, target, topk=(1,)):
26 """Computes the accuracy over the k top predictions for the specified values of k"""
27 with torch.no_grad():
28 maxk = max(topk)
29 batch_size = target.size(0)
30 _, pred = output.topk(maxk, 1, True, True)
31 pred = pred.t()
32 correct = pred.eq(target.view(1, -1).expand_as(pred))
33 res = []
34 for k in topk:
35 correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
36 res.append(correct_k.mul_(100.0 / batch_size))
37 return res
38
39def load_pretrained_weights(model, checkpoint):
40 """Load pretrianed weights to model

Callers 2

validateFunction · 0.85
train_with_configFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected