当前位置: 首页 > 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

相关文章:

  • 微信小程序,基于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库【持续更新】
  • 国家核安全局局长:我国核电进入大规模建设高峰期,在建规模超其他国家总和
  • 规范涉企案件审判执行工作,最高法今天发布通知
  • 我驻阿巴斯总领馆:将持续跟踪港口爆炸事件进展,全力确保中方人员安全
  • 三大交易所修订股票上市规则:明确关键少数责任,强化中小股东保障
  • 明查|把太平洋垃圾污染问题甩锅中国,特朗普用的是P过的图
  • 龚曙光:散文家永远只有一个视角,就是“我与时代”