当前位置: 首页 > 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.xdnf.cn/news/164845.html

相关文章:

  • docker 常用配置
  • 信息系统项目管理工程师备考计算类真题讲解十
  • 数位 DP 详解
  • Python并行计算:2.Python多线程编程:threading模块详解与守护线程实战
  • B3791 [信息与未来 2023] 电路布线
  • c++-模板
  • 2.4.5goweb项目上传到csdn的git仓库
  • 【量化交易笔记】17.多因子的线性回归模型策略
  • 提取office最强悍的软件
  • asammdf 库的文件操作和数据导出:高效管理 MDF 文件
  • 刚体运动 (位置向量 - 旋转矩阵) 笔记 1.1~1.3 (台大机器人学-林沛群)
  • 职场十二法则-马方
  • AnimateCC教学:元件旋转当中平移
  • 桥接模式(Bridge Pattern)详解
  • 从OpenAI收购实时数据引擎揭示AI数据库进化方向
  • ARM架构的微控制器总线矩阵仲裁策略
  • Java基础语法10分钟速成
  • JAVA:线程安全问题及解决方案
  • Centos7系统防火墙使用教程
  • 【JavaScript】自增和自减、逻辑运算符
  • 五年经验Java开发如何破局创业
  • L1-5 这是字符串题
  • # **DeepSeek 保姆级使用教程**
  • Redis数据结构SDS,IntSet,Dict
  • Java—— 五道算法水题
  • 强化学习基础
  • Python AI图像生成方案指南
  • Axure疑难杂症:全局变量典型应用及思考逻辑(玩转全局变量)
  • 剑指offer经典题目(六)
  • 做的一些题目的答案和自己的一些思考