当前位置: 首页 > news >正文

ultralytics 目标检测 混淆矩阵 背景图像 没被记录

修改

utils/metrics.py

ConfusionMatrix

    def process_batch(self, detections, gt_bboxes, gt_cls):"""Update confusion matrix for object detection task.Args:detections (Array[N, 6] | Array[N, 7]): Detected bounding boxes and their associated information.Each row should contain (x1, y1, x2, y2, conf, class)or with an additional element `angle` when it's obb.gt_bboxes (Array[M, 4]| Array[N, 5]): Ground truth bounding boxes with xyxy/xyxyr format.gt_cls (Array[M]): The class labels."""if gt_cls.shape[0] == 0:  # Check if labels is emptyif detections is not None:detections = detections[detections[:, 4] > self.conf]if detections.shape[0] == 0:self.matrix[self.nc, self.nc] += 1  # true backgroundelse:detection_classes = detections[:, 5].int()for dc in detection_classes:self.matrix[dc, self.nc] += 1  # false positivesreturnif detections is None:gt_classes = gt_cls.int()for gc in gt_classes:self.matrix[self.nc, gc] += 1  # background FNreturndetections = detections[detections[:, 4] > self.conf]gt_classes = gt_cls.int()detection_classes = detections[:, 5].int()is_obb = detections.shape[1] == 7 and gt_bboxes.shape[1] == 5  # with additional `angle` dimensioniou = (batch_probiou(gt_bboxes, torch.cat([detections[:, :4], detections[:, -1:]], dim=-1))if is_obbelse box_iou(gt_bboxes, detections[:, :4]))x = torch.where(iou > self.iou_thres)if x[0].shape[0]:matches = torch.cat((torch.stack(x, 1), iou[x[0], x[1]][:, None]), 1).cpu().numpy()if x[0].shape[0] > 1:matches = matches[matches[:, 2].argsort()[::-1]]matches = matches[np.unique(matches[:, 1], return_index=True)[1]]matches = matches[matches[:, 2].argsort()[::-1]]matches = matches[np.unique(matches[:, 0], return_index=True)[1]]else:matches = np.zeros((0, 3))n = matches.shape[0] > 0m0, m1, _ = matches.transpose().astype(int)for i, gc in enumerate(gt_classes):j = m0 == iif n and sum(j) == 1:self.matrix[detection_classes[m1[j]], gc] += 1  # correctelse:self.matrix[self.nc, gc] += 1  # true backgroundfor i, dc in enumerate(detection_classes):if not any(m1 == i):self.matrix[dc, self.nc] += 1  # predicted background
http://www.dtcms.com/a/156670.html

相关文章:

  • 微信小程序,基于uni-app的轮播图制作,轮播图本地文件图片预览
  • 文件操作及读写-爪哇版
  • 关于flink两阶段提交高并发下程序卡住问题
  • 【C++11】Lambda表达式
  • WPF大数据展示与分析性能优化方向及代码示例
  • 导览项目KD-Tree最近地点搜索优化
  • 用高德API提取广州地铁线路(shp、excel)
  • 【优选算法 | 滑动窗口】滑动窗口算法:高效处理子数组和子串问题
  • WPF核心技术解析与使用示例
  • WPF框架中异步、多线程、高性能、零拷贝技术的应用示例
  • 二、信息时代社会结构的转变
  • 我爱学算法之—— 二分查找(上)
  • 力扣HOT100——102.二叉树层序遍历
  • 解构与重构:“整体部分”视角下的软件开发思维范式
  • File,IO流,字符集
  • 25【干货】在Arcgis中根据字段属性重新排序并自动编号的方法(二)
  • 基于Tcp协议的应用层协议定制
  • Flask + ajax上传文件(三)--图片上传与OCR识别
  • 安服实习面试面经总结(也适合hvv蓝初)
  • 坚果派已适配的鸿蒙版flutter库【持续更新】
  • 什么是Lua模块?你会如何使用NGINX的Lua模块来定制请求处理流程?
  • 从“拼凑”到“构建”:大语言模型系统设计指南!
  • 【开源】基于51单片机的温湿度检测报警系统
  • WPF实现类似Microsoft Visual Studio2022界面效果及动态生成界面技术
  • 矫平机终极指南:特殊材料处理、工艺链协同与全球供应链管理
  • AI日报 - 2025年04月26日
  • 嵌入式学习笔记 - HAL_xxx_MspInit(xxx);函数
  • Prometheus、Zabbix和Nagios针对100个节点的部署设计架构图
  • Python基于Django的全国二手房可视化分析系统【附源码】
  • 2025第十六届蓝桥杯大赛(软件赛)网络安全赛 Writeup