计算CP、CR、CF1、OP、OR、OF1和mAP的top-3评价指标

# -*- coding: utf-8 -*-
import numpy as np#  CP CR CF1 OP OR OF1  mAP 的函数返回值
def calculate_metrics(labels, preds):mAP = calculate_mAP(labels, preds)pc_top3, rc_top3, f1c_top3, po_top3, ro_top3, f1o_top3 = calculate_top3_metrics(labels, preds) # top-3return {'pc_top3': pc_top3, 'rc_top3': rc_top3, 'f1c_top3': f1c_top3,'po_top3': po_top3, 'ro_top3': ro_top3, 'f1o_top3': f1o_top3, 'mAP': mAP}# top-3排序的标签
def calculate_top3_metrics(labels, preds):no_examples = labels.shape[0]top3 = np.zeros_like(preds)for ind_example in range(no_examples):top_pred_inds = np.argsort(preds[ind_example])[::-1]for k in range(3):top3[ind_example, top_pred_inds[k]] = 1pc_top3, rc_top3, f1c_top3 = prec_rec_f1(labels, top3)po_top3, ro_top3, f1o_top3 = prec_rec_f1(labels.flatten(), top3.flatten())return pc_top3, rc_top3, f1c_top3, po_top3, ro_top3, f1o_top3def prec_rec_f1(labels, pred_labels):eps = np.finfo(np.float32).epstp = labels * pred_labelsif len(labels.shape) == 2:no_tp = np.sum(tp, axis=1) + epsno_pred = np.sum(pred_labels, axis=1) + epsno_pos = np.sum(labels, axis=1) + epselif len(labels.shape) == 1:no_tp = np.sum(tp) + epsno_pred = np.sum(pred_labels) + epsno_pos = np.sum(labels) + epsprec_class = no_tp / no_pred + epsrec_class = no_tp / no_pos + epsf1_class = 2 * prec_class * rec_class / (prec_class + rec_class)return 100 * np.mean(prec_class), 100 * np.mean(rec_class), 100 * np.mean(f1_class)# 计算mAP
def calculate_mAP(labels, preds):no_examples = labels.shape[0]no_classes = labels.shape[1]ap_scores = np.empty((no_classes), dtype=np.float)for ind_class in range(no_classes):ground_truth = labels[:, ind_class]out = preds[:, ind_class]sorted_inds = np.argsort(out)[::-1] # in descending ordertp = ground_truth[sorted_inds]fp = 1 - ground_truth[sorted_inds]tp = np.cumsum(tp)fp = np.cumsum(fp)rec = tp / np.sum(ground_truth)prec = tp / (fp + tp)rec = np.insert(rec, 0, 0)rec = np.append(rec, 1)prec = np.insert(prec, 0, 0)prec = np.append(prec, 0)for ind in range(no_examples, -1, -1):prec[ind] = max(prec[ind], prec[ind + 1])inds = np.where(rec[1:] != rec[:-1])[0] + 1ap_scores[ind_class] = np.sum((rec[inds] - rec[inds - 1]) * prec[inds])return 100 * np.mean(ap_scores)

计算CP、CR、CF1、OP、OR、OF1和mAP的top-3评价指标相关推荐

  1. c语言 运算符op,1 简单计算器。请编写一个程序计算表达式:datal op data2的值。其中op为运算符+、—、*、/。...

    满意答案 770vivozf 2013.03.02 采纳率:43%    等级:9 已帮助:769人 1.简单计算器.请编写一个程序计算表达式:datal op data2的值.其中op为运算符+.- ...

  2. 训练 open-mmlab/mmclassification

    代码下载: github: https://github.com/open-mmlab/mmclassification 确定模型 resnet18 点击configs->resnet18_8* ...

  3. 博客文章总目录-祥瑞的技术博客

    直接点击标题进入文章. 博客文章总目录-邢翔瑞的技术博客 邮件地址:1057945230@qq.com 每日任务繁忙,如果博主能够解答的问题乐意解答.但是如果问题博主不太了解或者太过细节复杂,恕不能详 ...

  4. mmcls多标签分类实战(三):多标签分类指标

    前面两篇分别介绍了制作多标签数据,resnet多标签分类.接下来,我将介绍多标签分类的指标并分享一些关于多标签分类的细节,即如何操作可以提点. 在此之前,想提一下损失函数cross_entropy与b ...

  5. MATLAB计算气象水文要素年内分配指数

    MATLAB计算气象水文要素年内分配指数 降水/径流等水文要素年内分配指标 1 不均匀系数nuniformity coefficient (Cn) 1.1 原理 1.2 MATLAB代码 1.3 案例 ...

  6. 『矩阵论笔记』张量CP分解的详细数学推导以及Python实现

    张量CP分解的详细数学推导以及Python实现! 文章目录 一. 张量的基本概念 1.1 张量定义以及张量空间 1.2 阶和纤维(fiber)及切片 1.3 内积和范数及秩一张量/可合张量 1.4 超 ...

  7. 【张量分解(二)】CP分解

    本文是对论文Tensor Decompositions and Applications进行了翻译.整理.筛选和适当的补充,如何希望深入理解可以阅读原文. 相关文章: [张量分解(一)]符号与基础知识 ...

  8. 张量CP分解原理及Python实现

    目录 张量分解 数学符号说明 CP分解 基本概念 ALS-CP 公式推导 程序实现 附加说明 BP-CP 公式推导 程序实现 张量分解 参考文献:Kolda TG, Bader BW. Tensor ...

  9. 如何在框架外部自定义C++ OP

    如何在框架外部自定义C++ OP 通常,如果PaddlePaddle的Operator(OP)库中没有所需要的操作,建议先尝试使用已有的OP组合,如果无法组合出您需要的操作,可以尝试使用paddle. ...

最新文章

  1. Fedora15使用笔记
  2. 电源适配器变压器计算与元器件选型、细,全!【上篇-适配器设计计算23步骤】...
  3. libmemcached安装报错
  4. 415. Add Strings 字符串相加
  5. C++学习笔记-----继承体系中函数的重载,覆盖和隐藏的区别
  6. 业界分享 | 百度图神经网络实践
  7. synchronized实现
  8. iOS开发之UITableView全面解析
  9. 1067. Sort with Swap(0,*) (25)
  10. HTTP的概念以及请求消息的数据格式
  11. 用gambit学博弈论--完全信息动态博弈(一)
  12. padavan固件如何设置打印机
  13. iOS RSA加签 验签 与Java同步 pkcs8 pkcs1
  14. 蔡为东:行之有效的IT技术团队管理实践
  15. oracle怎么关联表查询语句,Oracle数据库的多表关联查询SQL语句
  16. iOS开发 适配iPhone XS Max/iPhone XR
  17. vivado和modelsim联合仿真,提示giving up waiting on lock,error:verilog compiler exiting解决方法
  18. js 中如何筛选处理符合条件的数据
  19. WLAN没有有效的IP配置,无Internet安全(开放)
  20. 软件测试工作面试的74个常见问题

热门文章

  1. 关于WIN10系统无法打开CHM文件
  2. 2022-06-06 FUSE用户态文件系统
  3. 腾讯云部署Hebe节点教程
  4. 2d游戏设计,pygame 游戏开发
  5. t检验自由度的意义_两独立t检验的自由度为n-2()
  6. Rancher 磁盘空间不足问题处理
  7. 杰理AC6965E开发资料共享
  8. 深度学习和神经网络的介绍
  9. 下载整个网站 有什么工具可以下载整个网站的内容吗?
  10. 【Nature 子刊】I型HLA基因中和癌症相关的体细胞突变--转载