MCPcopy Create free account
hub / github.com/pytorch/executorch / solve

Function solve

examples/qualcomm/utils.py:98–103  ·  view source on GitHub ↗
(prob, target, k)

Source from the content-addressed store, hash-verified

96
97def topk_accuracy(predictions, targets, k):
98 def solve(prob, target, k):
99 _, indices = torch.topk(prob, k=k, sorted=True)
100 golden = torch.reshape(target, [-1, 1])
101 correct = (golden == indices) * 1.0
102 top_k_accuracy = torch.mean(correct) * k
103 return top_k_accuracy
104
105 cnt = 0
106 for index, pred in enumerate(predictions):

Callers 1

topk_accuracyFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected