MCPcopy Create free account
hub / github.com/OpenDriveLab/ReSim / accuracy

Function accuracy

SwissArmyTransformer/examples/yolos/util/misc.py:432–447  ·  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

430
431@torch.no_grad()
432def accuracy(output, target, topk=(1,)):
433 """Computes the precision@k for the specified values of k"""
434 if target.numel() == 0:
435 return [torch.zeros([], device=output.device)]
436 maxk = max(topk)
437 batch_size = target.size(0)
438
439 _, pred = output.topk(maxk, 1, True, True)
440 pred = pred.t()
441 correct = pred.eq(target.view(1, -1).expand_as(pred))
442
443 res = []
444 for k in topk:
445 correct_k = correct[:k].view(-1).float().sum(0)
446 res.append(correct_k.mul_(100.0 / batch_size))
447 return res
448
449
450def interpolate(input, size=None, scale_factor=None, mode="nearest", align_corners=None):

Callers 1

loss_labelsMethod · 0.90

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected