MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / accuracy

Function accuracy

utils.py:482–489  ·  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

480
481
482def accuracy(output, target, topk=(1,)):
483 """Computes the accuracy over the k top predictions for the specified values of k"""
484 maxk = max(topk)
485 batch_size = target.size(0)
486 _, pred = output.topk(maxk, 1, True, True)
487 pred = pred.t()
488 correct = pred.eq(target.reshape(1, -1).expand_as(pred))
489 return [correct[:k].reshape(-1).float().sum(0) * 100. / batch_size for k in topk]
490
491
492def _no_grad_trunc_normal_(tensor, mean, std, a, b):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected