def accuracy(output, target, topk=(<NUM_LIT:1>,)):
with torch.no_grad():<EOL><INDENT>maxk = max(topk)<EOL>batch_size = target.size(<NUM_LIT:0>)<EOL>_, pred = output.topk(maxk, <NUM_LIT:1>, True, True)<EOL>pred = pred.t()<EOL>correct = pred.eq(target[None])<EOL>res = []<EOL>for k in topk:<EOL><INDENT>correct_k = correct[:k].flatten().sum(dtype=torch.float32)<EOL>res.append(correct_k * (<NUM_LIT> / batch_size))<EOL><DEDENT>return res<EOL><DEDENT>
Computes the accuracy over the k top predictions for the specified values of k