Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuyanyi committed Oct 20, 2022
1 parent 2b7c86d commit 5c5eeec
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions mmrotate/evaluation/metrics/rotated_coco_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import cv2
import numpy as np
import pycocotools.mask as maskUtils
from mmcv.ops import box_iou_rotated
from mmdet.datasets.api_wrappers import COCO
from mmdet.evaluation import CocoMetric
Expand All @@ -27,7 +28,7 @@ def qbox2rbox_list(boxes: list) -> list:
boxes (list): Quadrilateral box list with shape of (8).
Returns:
Tensor: Rotated box list with shape of (5).
List: Rotated box list with shape of (5).
"""
pts = np.array(boxes, dtype=np.float32).reshape(4, 2)
(x, y), (w, h), angle = cv2.minAreaRect(pts)
Expand All @@ -52,16 +53,24 @@ def computeIoU(self, imgId, catId):
if len(dt) > p.maxDets[-1]:
dt = dt[0:p.maxDets[-1]]

# TODO add support for segm
assert p.iouType == 'bbox', 'unsupported iouType for iou computation'

g = [g['bbox'] for g in gt]
d = [d['bbox'] for d in dt]

g = RotatedBoxes(g).tensor
d = RotatedBoxes(d).tensor
if p.iouType == 'segm':
# For segm, its same with original COCOeval
g = [g['segmentation'] for g in gt]
d = [d['segmentation'] for d in dt]
# compute iou between each dt and gt region
iscrowd = [int(o['iscrowd']) for o in gt]
ious = maskUtils.iou(d, g, iscrowd)
elif p.iouType == 'bbox':
# Modified for Rotated Box
g = [g['bbox'] for g in gt]
d = [d['bbox'] for d in dt]
# Convert List[List[float]] to Tensor for iou compute
g = RotatedBoxes(g).tensor
d = RotatedBoxes(d).tensor
ious = box_iou_rotated(d, g)
else:
raise Exception('unknown iouType for iou computation')

ious = box_iou_rotated(d, g)
return ious


Expand Down Expand Up @@ -165,13 +174,6 @@ def gt_to_coco_json(self, gt_dicts: Sequence[dict],
for ann in gt_dict['anns']:
label = ann['bbox_label']
bbox = ann['bbox']
# coco_bbox = [
# bbox[0],
# bbox[1],
# bbox[2] - bbox[0],
# bbox[3] - bbox[1],
# ]

coco_bbox = qbox2rbox_list(bbox)

annotation = dict(
Expand Down

0 comments on commit 5c5eeec

Please sign in to comment.