当前位置: 首页 > 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库【持续更新】
  • 短剧迷|《权宠》一出,《名不虚传》
  • 永辉超市回应顾客结算时被“反向抹零”:整改并补偿
  • 神舟十九号航天员乘组平安抵京
  • 国务院食安办:加强五一假期食品生产、销售、餐饮服务环节监管
  • “80后”商洛市委副书记、市政府党组副书记赵孝任商洛市副市长
  • 体重管理门诊来了,瘦不下来的我们有救了?|健康有方FM