MCPcopy Create free account
hub / github.com/TPCD/DCCL / accuracy

Function accuracy

project_utils/cluster_utils.py:172–186  ·  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

170
171
172def accuracy(output, target, topk=(1,)):
173 """Computes the accuracy over the k top predictions for the specified values of k"""
174 with torch.no_grad():
175 maxk = max(topk)
176 batch_size = target.size(0)
177
178 _, pred = output.topk(maxk, 1, True, True)
179 pred = pred.t()
180 correct = pred.eq(target.view(1, -1).expand_as(pred))
181
182 res = []
183 for k in topk:
184 correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
185 res.append(correct_k.mul_(100.0 / batch_size))
186 return res
187
188
189def seed_torch(seed=1029):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected