Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix confusion_matrix #870

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions tools/analysis_tools/confusion_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

import matplotlib.pyplot as plt
import numpy as np
import torch
from matplotlib.ticker import MultipleLocator
from mmcv.ops import nms_rotated
from mmdet.registry import DATASETS
from mmengine import Config, DictAction
from mmengine.fileio import load
from mmengine.utils import ProgressBar

from mmrotate.structures.bbox import rbbox_overlaps
from mmrotate.structures.bbox import qbox2rbox, rbbox_overlaps
from mmrotate.utils import register_all_modules


Expand Down Expand Up @@ -121,6 +122,12 @@ def analyze_per_img_dets(confusion_matrix,
gt_labels.append(gt['bbox_label'])

gt_bboxes = np.array(gt_bboxes)
# By default gt_bboxes is qbox not rbox
# rbbox_overlaps does not support ndarray input
# add .float to avoid opencv error
gt_bboxes = torch.from_numpy(gt_bboxes).float()
gt_bboxes = qbox2rbox(gt_bboxes)

gt_labels = np.array(gt_labels)

unique_label = np.unique(result['labels'].numpy())
Expand All @@ -130,11 +137,14 @@ def analyze_per_img_dets(confusion_matrix,
det_bboxes = result['bboxes'][mask].numpy()
det_scores = result['scores'][mask].numpy()

# rbbox_overlaps and nms_rotated does not support ndarray input
det_bboxes = torch.from_numpy(det_bboxes)
det_scores = torch.from_numpy(det_scores)

if nms_iou_thr:
det_bboxes, _ = nms_rotated(det_bboxes, det_scores, nms_iou_thr)
ious = rbbox_overlaps(det_bboxes[:, :5], gt_bboxes)
for i, det_bbox in enumerate(det_bboxes):
score = det_bbox[5]
for i, score in enumerate(det_scores):
det_match = 0
if score >= score_thr:
for j, gt_label in enumerate(gt_labels):
Expand Down