Unverified Commit e1f695d3 authored by xizaoqu's avatar xizaoqu Committed by GitHub
Browse files

[Fix] Fix the bug of counting ignore index in IOU in seg_eval (#2229)

* fix seg_eval

* add test for the bug

* update

* update

* update
parent 12c3b19d
...@@ -99,6 +99,9 @@ def seg_eval(gt_labels, seg_preds, label2cat, ignore_index, logger=None): ...@@ -99,6 +99,9 @@ def seg_eval(gt_labels, seg_preds, label2cat, ignore_index, logger=None):
hist_list.append(fast_hist(pred_seg, gt_seg, num_classes)) hist_list.append(fast_hist(pred_seg, gt_seg, num_classes))
iou = per_class_iou(sum(hist_list)) iou = per_class_iou(sum(hist_list))
# if ignore_index is in iou, replace it with nan
if ignore_index < len(iou):
iou[ignore_index] = np.nan
miou = np.nanmean(iou) miou = np.nanmean(iou)
acc = get_acc(sum(hist_list)) acc = get_acc(sum(hist_list))
acc_cls = get_acc_cls(sum(hist_list)) acc_cls = get_acc_cls(sum(hist_list))
......
...@@ -11,13 +11,12 @@ def test_indoor_eval(): ...@@ -11,13 +11,12 @@ def test_indoor_eval():
pytest.skip() pytest.skip()
seg_preds = [ seg_preds = [
np.array([ np.array([
0, 0, 1, 0, 0, 2, 1, 3, 1, 2, 1, 0, 2, 2, 2, 2, 1, 3, 0, 3, 3, 3, 3 0, 0, 1, 0, 0, 2, 1, 3, 1, 2, 1, 0, 2, 2, 2, 2, 1, 3, 0, 3, 3, 4, 0
]) ])
] ]
gt_labels = [ gt_labels = [
np.array([ np.array([
0, 0, 0, 255, 0, 0, 1, 1, 1, 255, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 0, 0, 0, 4, 0, 0, 1, 1, 1, 4, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4
3, 255
]) ])
] ]
...@@ -26,8 +25,9 @@ def test_indoor_eval(): ...@@ -26,8 +25,9 @@ def test_indoor_eval():
1: 'bicycle', 1: 'bicycle',
2: 'motorcycle', 2: 'motorcycle',
3: 'truck', 3: 'truck',
4: 'unlabeled'
} }
ret_value = seg_eval(gt_labels, seg_preds, label2cat, ignore_index=255) ret_value = seg_eval(gt_labels, seg_preds, label2cat, ignore_index=4)
assert np.isclose(ret_value['car'], 0.428571429) assert np.isclose(ret_value['car'], 0.428571429)
assert np.isclose(ret_value['bicycle'], 0.428571429) assert np.isclose(ret_value['bicycle'], 0.428571429)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment