def accuracy(outputs, targets, topk=(1,)):
    """
    Get top-k accuracy on the data batch.
    """

    maxk = max(topk)
    batch_size = len(targets)
    _, predicts = outputs.topk(maxk, 1, True, True)
    predicts = predicts.t()
    correct = predicts.eq(targets.view(1, -1).expand_as(predicts))
    res = []
    for k in topk:
        correct_k = correct[:k].view(-1).float().sum(0)
        res.append(correct_k.mul_(1.0/batch_size).item())
    return res