Skip to content

Commit 64ad587

Browse files
authored
[Fix] Fix ignore class id from -1 to 255 in master (open-mmlab#2515)
## Motivation This fixes open-mmlab#2493. When the `label_map` is created, the index for ignored classes was being set to -1, whereas the index that is actually ignored is 255. This worked indirectly since -1 was underflowed to 255 when converting to uint8. The same fix was made in the 1.x by open-mmlab#2332 but this fix was never made to `master`. ## Modification The only small modification is setting the index of ignored classes to 255 instead of -1. ## Checklist - [x] Pre-commit or other linting tools are used to fix the potential lint issues. - _I've fixed all linting/pre-commit errors._ - [x] The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness. - _No unit tests need to be added. Unit tests that are affected were modified. - [x] If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D. - _I don't think this change affects MMDet or MMDet3D._ - [x] The documentation has been modified accordingly, like docstring or example tutorials. - _This change fixes an existing bug and doesn't require modifying any documentation/docstring._
1 parent 5d49918 commit 64ad587

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mmseg/datasets/custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def get_classes_and_palette(self, classes=None, palette=None):
349349
self.label_map = {}
350350
for i, c in enumerate(self.CLASSES):
351351
if c not in class_names:
352-
self.label_map[i] = -1
352+
self.label_map[i] = 255
353353
else:
354354
self.label_map[i] = class_names.index(c)
355355

@@ -364,7 +364,7 @@ def get_palette_for_custom_classes(self, class_names, palette=None):
364364
palette = []
365365
for old_id, new_id in sorted(
366366
self.label_map.items(), key=lambda x: x[1]):
367-
if new_id != -1:
367+
if new_id != 255:
368368
palette.append(self.PALETTE[old_id])
369369
palette = type(self.PALETTE)(palette)
370370

tests/test_data/test_loading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def test_load_seg_custom_classes(self):
187187
# classes=["A", "C", "D"] which removes class "B".
188188
label_map={
189189
0: 0,
190-
1: -1, # simulate removing class 1
190+
1: 255, # simulate removing class 1
191191
2: 1,
192192
3: 2
193193
},
@@ -204,7 +204,7 @@ def test_load_seg_custom_classes(self):
204204

205205
true_mask = np.ones_like(gt_array) * 255 # all zeros get mapped to 255
206206
true_mask[2:4, 2:4] = 0 # 1s are reduced to class 0 mapped to class 0
207-
true_mask[2:4, 6:8] = -1 # 2s are reduced to class 1 which is removed
207+
true_mask[2:4, 6:8] = 255 # 2s are reduced to class 1 which is removed
208208
true_mask[6:8, 2:4] = 1 # 3s are reduced to class 2 mapped to class 1
209209
true_mask[6:8, 6:8] = 2 # 4s are reduced to class 3 mapped to class 2
210210

0 commit comments

Comments
 (0)