Skip to content

Commit

Permalink
Return empty iou when ground truth *or* detection is empty
Browse files Browse the repository at this point in the history
Summary:
On horizontal box OCR datasets, d2go may fail in evaluation during the IoU calculation.

This happens when the detections are empty; the detections are empty when the image has been deleted, as in fbid [103133290522776](https://www.internalfb.com/intern/whatisthis/103133290522776), even though the the ground truth is non-empty. Therefore, in the case when `dt` OR `gt` is empty, we should return an empty list for the ious.

In addition, we should make sure the ious are type Tensor before calling `.cpu()`.

More context [here](https://fb.workplace.com/groups/277527419809135/posts/1376896089872257/?comment_id=1376905679871298&reply_comment_id=1377770513118148).

Reviewed By: Rechant

Differential Revision: D49613362

fbshipit-source-id: e2054f0ee28318a744e3259cc8949c00100d7b1f
  • Loading branch information
Pooja Sethi authored and facebook-github-bot committed Sep 26, 2023
1 parent 8c4a333 commit 1a4df4d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions detectron2/evaluation/rotated_coco_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ def compute_iou_dt_gt(self, dt, gt, is_crowd):
# This is the same as the classical COCO evaluation
return maskUtils.iou(dt, gt, is_crowd)

def computeIoU(self, imgId, catId):
def computeIoU(self, imgId: int, catId: int):
p = self.params
if p.useCats:
gt = self._gts[imgId, catId]
dt = self._dts[imgId, catId]
else:
gt = [_ for cId in p.catIds for _ in self._gts[imgId, cId]]
dt = [_ for cId in p.catIds for _ in self._dts[imgId, cId]]
if len(gt) == 0 and len(dt) == 0:

if len(gt) == 0 or len(dt) == 0:
return []

inds = np.argsort([-d["score"] for d in dt], kind="mergesort")
dt = [dt[i] for i in inds]
if len(dt) > p.maxDets[-1]:
Expand Down

0 comments on commit 1a4df4d

Please sign in to comment.