MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / accuracy

Function accuracy

Image_Classification/src/train.py:483–495  ·  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

481
482
483def accuracy(output, target, topk=(1,)):
484 """Computes the precision@k for the specified values of k"""
485 maxk = max(topk)
486 batch_size = target.size(0)
487 _, pred = output.topk(maxk, 1, largest=True, sorted=True)
488 pred = pred.t()
489 correct = pred.eq(target.view(1, -1).expand_as(pred))
490
491 res = []
492 for k in topk:
493 correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
494 res.append(correct_k.mul_(100.0 / batch_size))
495 return res
496
497
498def setup_dirs(args: APNamespace) -> Tuple[Path, Path, Path, Path, Path | None]:

Callers 2

epoch_iterationMethod · 0.85
validateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected