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

Function topk_accuracy

examples/qualcomm/utils.py:97–109  ·  view source on GitHub ↗
(predictions, targets, k)

Source from the content-addressed store, hash-verified

95
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):
107 cnt += solve(torch.from_numpy(pred), targets[index], k)
108
109 return cnt * 100.0 / len(predictions)
110
111
112def segmentation_metrics(predictions, targets, classes):

Callers 15

mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 1

solveFunction · 0.70

Tested by

no test coverage detected