日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

目标检测计算mAP,AP,Recall,Precision的计算方式和代码(YOLO和FastRCNN等)

發布時間:2023/11/27 生活经验 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 目标检测计算mAP,AP,Recall,Precision的计算方式和代码(YOLO和FastRCNN等) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

目標檢測中計算mAP是較為復雜的,并不是很多講解中說的那個計算precision和recall,然后總的ground truth 目標和檢測出的真實目標做除法就可以了。而是需要構建precision和recall 曲線,然后計算曲線面積。

一下是代碼,可以去相關網站查看計算過程,過程較為復雜。

mAP計算詳解?GitHub - rafaelpadilla/Object-Detection-Metrics: Most popular metrics used to evaluate object detection algorithms.

FastRCNN的mAP計算過程。GitHub - rbgirshick/py-faster-rcnn: Faster R-CNN (Python implementation) -- see https://github.com/ShaoqingRen/faster_rcnn for the official MATLAB version

def ap_per_class(tp, conf, pred_cls, target_cls):""" Compute the average precision, given the recall and precision curves.Source: https://github.com/rafaelpadilla/Object-Detection-Metrics.# Argumentstp:    True positives (list).conf:  Objectness value from 0-1 (list).pred_cls: Predicted object classes (list).target_cls: True object classes (list).# ReturnsThe average precision as computed in py-faster-rcnn."""# Sort by objectnessi = np.argsort(-conf)tp, conf, pred_cls = tp[i], conf[i], pred_cls[i]# Find unique classesunique_classes = np.unique(np.concatenate((pred_cls, target_cls), 0))# Create Precision-Recall curve and compute AP for each classap, p, r = [], [], []for c in unique_classes:i = pred_cls == cn_gt = sum(target_cls == c)  # Number of ground truth objectsn_p = sum(i)  # Number of predicted objectsif (n_p == 0) and (n_gt == 0):continueelif (n_p == 0) or (n_gt == 0):ap.append(0)r.append(0)p.append(0)else:# Accumulate FPs and TPsfpc = np.cumsum(1 - tp[i])tpc = np.cumsum(tp[i])# Recallrecall_curve = tpc / (n_gt + 1e-16)r.append(tpc[-1] / (n_gt + 1e-16))# Precisionprecision_curve = tpc / (tpc + fpc)p.append(tpc[-1] / (tpc[-1] + fpc[-1]))# AP from recall-precision curveap.append(compute_ap(recall_curve, precision_curve))return np.array(ap), unique_classes.astype('int32'), np.array(r), np.array(p)def compute_ap(recall, precision):""" Compute the average precision, given the recall and precision curves.Source: https://github.com/rbgirshick/py-faster-rcnn.# Argumentsrecall:    The recall curve (list).precision: The precision curve (list).# ReturnsThe average precision as computed in py-faster-rcnn."""# correct AP calculation# first append sentinel values at the endmrec = np.concatenate(([0.], recall, [1.]))mpre = np.concatenate(([0.], precision, [0.]))# compute the precision envelopefor 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 valuei = np.where(mrec[1:] != mrec[:-1])[0]# and sum (\Delta recall) * precap = np.sum((mrec[i + 1] - mrec[i]) * mpre[i + 1])return ap

如果有用,記得點贊👍加收藏哦。!!!!

總結

以上是生活随笔為你收集整理的目标检测计算mAP,AP,Recall,Precision的计算方式和代码(YOLO和FastRCNN等)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。