AP AR

server/2025/3/13 17:49:55/

混淆矩阵

真实值=正例真实值=负例
预测值=正例TPFP
预测值=负例FNTN

(根据阈值预测)

P精确度计算:TP/(TP+FP)

R召回率计算:TP/(TP+FN)

AP

综合考虑P R

根据不同的阈值计算出不同的PR组合, 画出PR曲线,计算曲线下面积即为PR

(所有点插值法计算,简单来讲就是近似计算小矩形面积和)

import numpy as np
import matplotlib.pyplot as pltdef calculate_precision_recall(confusion_matrices):#计算P Rrecall = []precision = []for tp, fp, fn in confusion_matrices:if tp + fp == 0:p = 0.0else:p = tp / (tp + fp)if tp + fn == 0:r = 0.0else:r = tp / (tp + fn)precision.append(p)recall.append(r)return recall, precisiondef calculate_ap_all_points(recall, precision):#所有点插值法计算面积recall = np.concatenate(([0.], recall, [1.]))precision = np.concatenate(([0.], precision, [0.]))for i in range(precision.size - 1, 0, -1):precision[i - 1] = np.maximum(precision[i - 1], precision[i])ap = np.sum(np.diff(recall) * precision[1:])return ap# 示例 (每个元素为 [TP, FP, FN])
confusion_matrices = [[10, 0, 0],  # 置信度阈值1[8, 1, 2],  # 置信度阈值2[6, 2, 4],  # 置信度阈值3[5, 3, 5],  # 置信度阈值4[4, 4, 6],  # 置信度阈值5[3, 7, 7],  # 置信度阈值6
]# 计算精确率和召回率
recall, precision = calculate_precision_recall(confusion_matrices)# 计算AP
ap = calculate_ap_all_points(recall, precision)
print(f"平均精度 (AP): {ap}")# 绘制精确率-召回率曲线
plt.plot(recall, precision, marker='o')
plt.xlabel('Recall')
plt.ylabel('Precision')
plt.title('Precision-Recall Curve (AP = {:.3f})'.format(ap))
plt.grid(True)
plt.show()

AR

平均召回率

主要是考虑漏检,专注于R

import numpy as npdef calculate_ar(true_positives, false_negatives, max_detections):recall_values = []for tp, fn in zip(true_positives, false_negatives):if tp + fn == 0:recall = 0.0else:recall = tp / (tp + fn)recall_values.append(recall)# 假设我们只考虑前 max_detections 个召回率值if len(recall_values) > max_detections:recall_values = recall_values[:max_detections]if not recall_values:return 0.0ar = np.mean(recall_values)return ar# 示例数据
true_positives = [10, 8, 6, 5, 4, 3]  # TP
false_negatives = [0, 2, 4, 5, 6, 7]  # FP
max_detections = 5  # 最大检测次数# 计算AR
ar = calculate_ar(true_positives, false_negatives, max_detections)
print(f"平均召回率 (AR): {ar}")#计算maxDets 为10时候的AR
max_detections_2 = 10
ar_2 = calculate_ar(true_positives, false_negatives, max_detections_2)
print(f"平均召回率 (AR)maxDets为10 : {ar_2}")

平均精度(Average Precision,AP)以及AP50、AP75、APs、APm、APl、Box AP、Mask AP等不同阈值和细分类别的评估指标说明-CSDN博客


http://www.ppmy.cn/server/174680.html

相关文章

海康机器人搞工业机器人,我以为它忘记自己名字,作为技术,作为业务你跟不跟,机器视觉工程师搞视觉引导必须知道工业机器人四大坐标系

工业机器人的坐标系是编程、调试和操作的核心基础,不同坐标系决定了机器人的运动方式和参考基准。以下是工业机器人四大坐标系的详细解析,包括定义、功能、应用场景及注意事项: 关节坐标系(Joint Coordinates) 定义 以机器人各关节轴为独立运动单元,每个关节的旋转或直线…

读书笔记 - Spring Boot实战

读书笔记 - Spring Boot实战 第1章 入门Spring Boot精要1. 自动配置2. 起步依赖3. 命令行界面4. Actuator 使用Spring Initializr初始化Spring Boot项目 第2章 运用SpringBootSpringBootApplication配置应用程序属性指定基于功能的依赖覆盖起步依赖引入的传递依赖使用自动配置 …

项目上传到Gitee过程

在gitee上新建一个仓库 点击“克隆/下载”获取仓库地址 电脑上要装好git 在电脑本地文件夹右键“Git Bash Here” 依次执行如下命令 git init git remote add origin https://gitee.com/qlexcel/stm32-simple.git git pull origin master git add . git commit -m ‘init’…

DeepSeek与剪映短视频创作指南

DeepSeek(深度求索)作为一家专注实现AGI的中国公司,其技术可能涉及AI文本生成、图像处理等领域,结合剪映的智能剪辑功能,可以大幅提升短视频创作效率。以下是结合两者优势的详细创作步骤: 一、创意策划阶段…

严格把控K8S集群中的操作权限,为普通用户生成特定的kubeconfig文件

文章目录 前言一、背景二、证书和证书签名请求(了解)1.证书签名请求2.请求签名流程3.Kubernetes 签名者4.证书过期时间限制字段 二、脚本示例2.检查集群上下文及csr3.切换集群上下文,检查权限4.普通用户操作 总结 前言 使用并维护过K8S的ops/sre都知道,kubeconfig对于k8s的访问…

【CXX】6.2 str — rust::Str

Rust::Str 公共 API // rust/cxx.hclass Str final { public:Str() noexcept;Str(const Str &) noexcept;Str(const String &) noexcept;// 如果输入不是 UTF-8,抛出 std::invalid_argument 异常。Str(const std::string &);Str(const char *);Str(con…

线性表相关代码(顺序表+单链表)

线性表相关代码 线性表相关代码(算法命题重点)顺序存储链式存储单链表带头结点不带头结点 双链表循环链表静态链表 线性表相关代码(算法命题重点) 线性表作为一种基础且重要的数据结构,在算法领域中占据着关键地位&am…

go sync.Once 源码分析

sync.Once 是 Go 语言标准库中的一个同步原语,用于确保某个操作或函数在并发环境下只执行一次。它通常用于以下场景: 单例模式:确保全局只有一个实例对象,避免重复创建资源延迟初始化:在程序运行过程中,当…