Skip to content

Commit f3c1bc1

Browse files
Fix semantic errors in code for calculating IoU metrics in Segmentation evaluator.
Summary: While reading code for adding B-IoU metric for existing evaluator, discovered some semantic errors in existing code (iou_valid flag usage) and I fixed it. It's interesting that the issue has never been found / caught / reported. Reviewed By: rbgirshick Differential Revision: D37471657 fbshipit-source-id: 43b83b668e1ef04dba6fec355f4b7704a1a6cbea
1 parent abef4c0 commit f3c1bc1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

detectron2/evaluation/sem_seg_evaluation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,12 @@ def evaluate(self):
191191
pos_pred = np.sum(self._conf_matrix[:-1, :-1], axis=1).astype(np.float)
192192
acc_valid = pos_gt > 0
193193
acc[acc_valid] = tp[acc_valid] / pos_gt[acc_valid]
194-
iou_valid = (pos_gt + pos_pred) > 0
195194
union = pos_gt + pos_pred - tp
196-
iou[acc_valid] = tp[acc_valid] / union[acc_valid]
195+
iou_valid = np.logical_and(acc_valid, union > 0)
196+
iou[iou_valid] = tp[iou_valid] / union[iou_valid]
197197
macc = np.sum(acc[acc_valid]) / np.sum(acc_valid)
198-
miou = np.sum(iou[acc_valid]) / np.sum(iou_valid)
199-
fiou = np.sum(iou[acc_valid] * class_weights[acc_valid])
198+
miou = np.sum(iou[iou_valid]) / np.sum(iou_valid)
199+
fiou = np.sum(iou[iou_valid] * class_weights[iou_valid])
200200
pacc = np.sum(tp) / np.sum(pos_gt)
201201

202202
if self._compute_boundary_iou:

0 commit comments

Comments
 (0)