MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / accuracy

Function accuracy

PATH/core/models/decoders/losses/criterion.py:25–39  ·  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

23
24@torch.no_grad()
25def accuracy(output, target, topk=(1,)):
26 """Computes the precision@k for the specified values of k"""
27 if target.numel() == 0:
28 return [torch.zeros([], device=output.device)]
29 maxk = max(topk)
30 batch_size = target.size(0)
31 _, pred = output.topk(maxk, 1, True, True)
32 pred = pred.t()
33 correct = pred.eq(target.view(1, -1).expand_as(pred))
34
35 res = []
36 for k in topk:
37 correct_k = correct[:k].view(-1).float().sum(0)
38 res.append(correct_k.mul_(100.0 / batch_size))
39 return res
40
41
42def sigmoid_focal_loss(inputs, targets, num_boxes, alpha: float = 0.25, gamma: float = 2):

Callers 1

loss_labelsMethod · 0.70

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected