Skip to content

Commit ecef545

Browse files
kprokofieunwoosh
andauthored
Change categories mapping logic (#3946)
* change pre-filtering logic * Update src/otx/core/data/pre_filtering.py Co-authored-by: Eunwoo Shin <[email protected]> --------- Co-authored-by: Eunwoo Shin <[email protected]>
1 parent c7efcbc commit ecef545

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/otx/core/data/pre_filtering.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ def remove_unused_labels(dataset: DmDataset, data_format: str, ignore_index: int
8888
raise ValueError(msg)
8989
if len(used_labels) == len(original_categories):
9090
return dataset
91+
if data_format == "arrow" and max(used_labels) != len(original_categories) - 1:
92+
# we assume that empty label is always the last one. If it is not explicitly added to the dataset,
93+
# (not in the used labels) it will be filtered out.
94+
mapping = {cat: cat for cat in original_categories[:-1]}
95+
elif data_format == "arrow":
96+
# this mean that some other class wasn't annotated, we don't need to filter the object classes
97+
return dataset
98+
else:
99+
mapping = {original_categories[idx]: original_categories[idx] for idx in used_labels}
91100
msg = "There are unused labels in dataset, they will be filtered out before training."
92101
warnings.warn(msg, stacklevel=2)
93-
mapping = {original_categories[idx]: original_categories[idx] for idx in used_labels}
94102
return dataset.transform("remap_labels", mapping=mapping, default="delete")

0 commit comments

Comments
 (0)