Skip to content

Commit

Permalink
[FIX] bug of generator, which lead metric to nan when pre_eval=False
Browse files Browse the repository at this point in the history
Signed-off-by: FreyWang <[email protected]>
  • Loading branch information
FreyWang committed Sep 2, 2021
1 parent e6501a2 commit bf48690
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 0 additions & 2 deletions mmseg/core/evaluation/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@ def total_intersect_and_union(results,
ndarray: The prediction histogram on all classes.
ndarray: The ground truth histogram on all classes.
"""
num_imgs = len(results)
assert len(list(gt_seg_maps)) == num_imgs
total_area_intersect = torch.zeros((num_classes, ), dtype=torch.float64)
total_area_union = torch.zeros((num_classes, ), dtype=torch.float64)
total_area_pred_label = torch.zeros((num_classes, ), dtype=torch.float64)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_data/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def test_custom_dataset():
assert 'mPrecision' in eval_results
assert 'mRecall' in eval_results

assert not np.isnan(eval_results['mIoU'])
assert not np.isnan(eval_results['mDice'])
assert not np.isnan(eval_results['mAcc'])
assert not np.isnan(eval_results['aAcc'])
assert not np.isnan(eval_results['mFscore'])
assert not np.isnan(eval_results['mPrecision'])
assert not np.isnan(eval_results['mRecall'])

# test evaluation with pre-eval and the dataset.CLASSES is necessary
train_dataset.CLASSES = tuple(['a'] * 7)
pseudo_results = []
Expand Down Expand Up @@ -250,6 +258,14 @@ def test_custom_dataset():
assert 'mPrecision' in eval_results
assert 'mRecall' in eval_results

assert not np.isnan(eval_results['mIoU'])
assert not np.isnan(eval_results['mDice'])
assert not np.isnan(eval_results['mAcc'])
assert not np.isnan(eval_results['aAcc'])
assert not np.isnan(eval_results['mFscore'])
assert not np.isnan(eval_results['mPrecision'])
assert not np.isnan(eval_results['mRecall'])


@pytest.mark.parametrize('separate_eval', [True, False])
def test_eval_concat_custom_dataset(separate_eval):
Expand Down

0 comments on commit bf48690

Please sign in to comment.