欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > AP单类平均准确率

AP单类平均准确率

2025/5/26 7:31:23 来源:https://blog.csdn.net/qq_35732321/article/details/145434518  浏览:    关键词:AP单类平均准确率
        P_true   N_true
P_pred    TP      Fp
N_pred    FN      TNP       N
  1. TP(真正样本,与真实框IoU大于阈值的框) FP(假正样本,与真实框IoU小于阈值的框) TN(真负样本,背景) FN(假负样本,没有检测出的正样本)
  2. IoU:(A and B)/(A or B) A与B的交集除以A与B的并集
  3. precision:准确率,查全率。TP/(TP+FP)= TP/num_pred,数值越大,说明FP数量越少,准确率越高,但是没有考虑FN(可能有漏检)。
  4. recall:召回率,查准率。TP/(TP+FN)= TP/num_sample,数值越大,说明被检测到的正样本越多,效果越好,但是没有考虑FP(如果把背景也判断成前景,则效果不好)。
  5. F score:几何平均分,(BB+1)PR/(BBP+R),B用来调节PR的权重,当B=1,F1 score。 是precision和recall的加权,考虑两个评价指标的优劣。precision和recall是此消彼长的关系。
  6. Average Precision:单类平均准确率。是PR曲线的面积。
样本     置信度       正负样本    累计tp   累计fp   precision   recall
1 		 0.97 		 True 		 1 		 0 		 1.0 		 0.1
2 		 0.87 		 True 		 2 		 0 		 1.0 		 0.2
3 		 0.84 		 True 		 3 		 0 		 1.0 		 0.3
4 		 0.8 		 True 		 4 		 0 		 1.0 		 0.4
5 		 0.69 		 False 		 4 		 1 		 0.8 		 0.4
6 		 0.58 		 True 		 5 		 1 		 0.83 		 0.5
7 		 0.43 		 False 		 5 		 2 		 0.71 		 0.5
8 		 0.19 		 True 		 6 		 2 		 0.75 		 0.6
9 		 0.02 		 False 		 6 		 3 		 0.67 		 0.6
10 		 0.03 		 False 		 6 		 4 		 0.6 		 0.6

在这里插入图片描述

import numpy as np
img_ids = None
class_recs = None
BB = Nonend = len(img_ids)
thred = 0.5
npos = 100
tp = np.zeros(nd)
fp = np.zeros(nd)
for d in range(nd):R = class_recs[img_ids[d]]bb = BB[d,:].astype(float)      # 按照置信度排好序idx = -np.infBBGT = R['bbox'].astype(float)  # 真实框if BBGT.size>0:# 计算IoUx1y1 = np.maximum(BBGT[:,:2],bb[:2])x2y2 = np.maximum(BBGT[:, 2:], bb[2:])wh = np.maximum(x2y2-x1y1+1,0)inters = wh[0]*wh[1]bb_areas = (bb[2]-bb[0]+1.0)*(bb[3]-bb[1]+1.0)BBGT_ares = (BBGT[:,2]-BBGT[:,0]+1.0)*(BBGT[:,3]-BBGT[:,1]+1.0)ious = inters/(bb_areas+BBGT_ares-inters)iou = np.max(ious)idx = np.argmax(ious)if idx>thred:if not R['difficult'][idx]:if not R['det'][idx]:tp[d]=1.R['det'][idx]=1else:fp[d] = 1.else:fp[d] = 1.fp = np.cumum(fp)
tp = np.cumum(tp)
rec = tp/float(npos)
prec = tp/np.maximum(tp+fp,np.finfo(np.float64).eps)def voc_ap(rec,prec):mrec = np.concatenate(([0.],rec,[1.]))mpre = np.concatenate(([0.],prec,[0.]))for i in range(mpre.size-1,0,-1):mpre[i-1]=np.maximum(mpre[i-1],mpre[i])i = np.where(mpre[1:] != mpre[:-1])[0]ap = np.sum((mrec[i+1]-mrec[i])*mrec[i+1])return ap

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词