Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix ignore class id from -1 to 255 in master #2515

Merged
merged 2 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mmseg/datasets/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def get_classes_and_palette(self, classes=None, palette=None):
self.label_map = {}
for i, c in enumerate(self.CLASSES):
if c not in class_names:
self.label_map[i] = -1
self.label_map[i] = 255
else:
self.label_map[i] = class_names.index(c)

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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_data/test_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def test_load_seg_custom_classes(self):
# classes=["A", "C", "D"] which removes class "B".
label_map={
0: 0,
1: -1, # simulate removing class 1
1: 255, # simulate removing class 1
2: 1,
3: 2
},
Expand All @@ -204,7 +204,7 @@ def test_load_seg_custom_classes(self):

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

Expand Down