zoukankan      html  css  js  c++  java
  • fast、faster中ap值的计算

    def voc_ap(rec, prec, use_07_metric=False):
        """ ap = voc_ap(rec, prec, [use_07_metric])
        Compute VOC AP given precision and recall.
        If use_07_metric is true, uses the
        VOC 07 11 point method (default:False).
        """
        if use_07_metric:
            # 11 point metric
            ap = 0.
            for t in np.arange(0., 1.1, 0.1):
                if np.sum(rec >= t) == 0:
                    p = 0
                else:
                    p = np.max(prec[rec >= t])
                ap = ap + p / 11.
        else:
            # correct AP calculation
            # first append sentinel values at the end
            mrec = np.concatenate(([0.], rec, [1.]))
            mpre = np.concatenate(([0.], prec, [0.]))
    
            # compute the precision envelope
            for i in range(mpre.size - 1, 0, -1):
                mpre[i - 1] = np.maximum(mpre[i - 1], mpre[i])
    
            # to calculate area under PR curve, look for points
            # where X axis (recall) changes value
            i = np.where(mrec[1:] != mrec[:-1])[0]
    
            # and sum (Delta recall) * prec
            ap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])
    return ap
  • 相关阅读:
    华为ensp使用
    网络学习目录
    MySQL简介
    zip命令详解
    gzip命令详解
    unzip/tar命令详解
    tar命令详解
    ipython使用
    os, sys, stat 模块使用
    配置linux系统时区---解决ntp同步完时间不准问题
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/9273596.html
Copyright © 2011-2022 走看看