Skip to content

Commit bf48690

Browse files
committed
[FIX] bug of generator, which lead metric to nan when pre_eval=False
Signed-off-by: FreyWang <wangwxyz@qq.com>
1 parent e6501a2 commit bf48690

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

mmseg/core/evaluation/metrics.py

-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ def total_intersect_and_union(results,
112112
ndarray: The prediction histogram on all classes.
113113
ndarray: The ground truth histogram on all classes.
114114
"""
115-
num_imgs = len(results)
116-
assert len(list(gt_seg_maps)) == num_imgs
117115
total_area_intersect = torch.zeros((num_classes, ), dtype=torch.float64)
118116
total_area_union = torch.zeros((num_classes, ), dtype=torch.float64)
119117
total_area_pred_label = torch.zeros((num_classes, ), dtype=torch.float64)

tests/test_data/test_dataset.py

+16
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ def test_custom_dataset():
213213
assert 'mPrecision' in eval_results
214214
assert 'mRecall' in eval_results
215215

216+
assert not np.isnan(eval_results['mIoU'])
217+
assert not np.isnan(eval_results['mDice'])
218+
assert not np.isnan(eval_results['mAcc'])
219+
assert not np.isnan(eval_results['aAcc'])
220+
assert not np.isnan(eval_results['mFscore'])
221+
assert not np.isnan(eval_results['mPrecision'])
222+
assert not np.isnan(eval_results['mRecall'])
223+
216224
# test evaluation with pre-eval and the dataset.CLASSES is necessary
217225
train_dataset.CLASSES = tuple(['a'] * 7)
218226
pseudo_results = []
@@ -250,6 +258,14 @@ def test_custom_dataset():
250258
assert 'mPrecision' in eval_results
251259
assert 'mRecall' in eval_results
252260

261+
assert not np.isnan(eval_results['mIoU'])
262+
assert not np.isnan(eval_results['mDice'])
263+
assert not np.isnan(eval_results['mAcc'])
264+
assert not np.isnan(eval_results['aAcc'])
265+
assert not np.isnan(eval_results['mFscore'])
266+
assert not np.isnan(eval_results['mPrecision'])
267+
assert not np.isnan(eval_results['mRecall'])
268+
253269

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

0 commit comments

Comments
 (0)