{"nwo":"AlfredXiangWu\/LightCNN","sha":"8b33107e836374a892efecd149d2016170167fdd","path":"train.py","language":"python","identifier":"accuracy","parameters":"(output, target, topk=(1,))","argument_list":"","return_statement":"return res","docstring":"Computes the precision@k for the specified values of k","docstring_summary":"Computes the precision","docstring_tokens":["Computes","the","precision"],"function":"def accuracy(output, target, topk=(1,)):\n \"\"\"Computes the precision@k for the specified values of k\"\"\"\n maxk = max(topk)\n batch_size = target.size(0)\n\n _, pred = output.topk(maxk, 1, True, True)\n pred = pred.t()\n correct = pred.eq(target.view(1, -1).expand_as(pred))\n\n res = []\n for k in topk:\n correct_k = correct[:k].view(-1).float().sum(0)\n res.append(correct_k.mul_(100.0 \/ batch_size))\n return res","function_tokens":["def","accuracy","(","output",",","target",",","topk","=","(","1",",",")",")",":","maxk","=","max","(","topk",")","batch_size","=","target",".","size","(","0",")","_",",","pred","=","output",".","topk","(","maxk",",","1",",","True",",","True",")","pred","=","pred",".","t","(",")","correct","=","pred",".","eq","(","target",".","view","(","1",",","-","1",")",".","expand_as","(","pred",")",")","res","=","[","]","for","k","in","topk",":","correct_k","=","correct","[",":","k","]",".","view","(","-","1",")",".","float","(",")",".","sum","(","0",")","res",".","append","(","correct_k",".","mul_","(","100.0","\/","batch_size",")",")","return","res"],"url":"https:\/\/github.com\/AlfredXiangWu\/LightCNN\/blob\/8b33107e836374a892efecd149d2016170167fdd\/train.py#L269-L282"}