MCPcopy Create free account
hub / github.com/bic-L/MaxFormer / accuracy

Function accuracy

event/utils.py:162–177  ·  view source on GitHub ↗

Computes the accuracy over the k top predictions for the specified values of k

(output, target, topk=(1,))

Source from the content-addressed store, hash-verified

160
161
162def accuracy(output, target, topk=(1,)):
163 """Computes the accuracy over the k top predictions for the specified values of k"""
164 with torch.no_grad():
165 maxk = max(topk)
166 batch_size = target.size(0)
167
168 _, pred = output.topk(maxk, 1, True, True)
169 pred = pred.t()
170 # print(target[None])
171 correct = pred.eq(target[None])
172
173 res = []
174 for k in topk:
175 correct_k = correct[:k].flatten().sum(dtype=torch.float32)
176 res.append(correct_k * (100.0 / batch_size))
177 return res
178
179
180def mkdir(path):

Callers 2

evaluateFunction · 0.90
validateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected