Computes the accuracy over the k top predictions for the specified values of k
(output, target, topk=(1,))
| 480 | |
| 481 | |
| 482 | def 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 | |
| 492 | def _no_grad_trunc_normal_(tensor, mean, std, a, b): |
nothing calls this directly
no outgoing calls
no test coverage detected