美文网首页工作生活
图像分类的评价指标

图像分类的评价指标

作者: 顾北向南 | 来源:发表于2019-07-03 20:51 被阅读0次

    1. topk的度量

    def accuracy(output, target, topk=(1,)):
        """Computes the precision@k for the specified values of k"""
        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
    
     prec1, prec5 = accuracy(output.data, target, topk=(1, 5))
    

    2. 计算平均值

    class AverageMeter(object):
        """Computes and stores the average and current value"""
        def __init__(self):
            self.reset()
    
        def reset(self):
            self.val = 0
            self.avg = 0
            self.sum = 0
            self.count = 0
    
        def update(self, val, n=1):
            self.val = val
            self.sum += val * n
            self.count += n
            self.avg = self.sum / self.count
    

    相关文章

      网友评论

        本文标题:图像分类的评价指标

        本文链接:https://www.haomeiwen.com/subject/nrhhhctx.html