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 label mismatch of evaluation and validation with large dataset in semantic segmentation #1851

Merged
merged 9 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
10 changes: 7 additions & 3 deletions otx/algorithms/segmentation/adapters/mmseg/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(
self.label_map = None

dataset_labels = self.otx_dataset.get_labels(include_empty=False)
self.project_labels = self.filter_labels(dataset_labels, classes)
self.project_labels = sorted(self.filter_labels(dataset_labels, classes))
self.CLASSES, self.PALETTE = self.get_classes_and_palette(classes, None)

# Instead of using list data_infos as in CustomDataset, this implementation of dataset
Expand All @@ -144,8 +144,8 @@ def __init__(

@staticmethod
@check_input_parameters_type()
def filter_labels(all_labels: List[LabelEntity], label_names: List[str]):
"""Filtering Labels function."""
def filter_labels(all_labels: List[LabelEntity], label_names: List[str]) -> List[LabelEntity]:
"""Filter and collect actual label entities."""
filtered_labels = []
for label_name in label_names:
matches = [label for label in all_labels if label.name == label_name]
Expand Down Expand Up @@ -263,6 +263,10 @@ def __init__(self, **kwargs):
else:
classes = []
super().__init__(otx_dataset=otx_dataset, pipeline=pipeline, classes=classes)

# TODO [Soobee] : Need to align again when background label is removed
self.CLASSES = ["background"] + [label.name for label in self.project_labels]

if self.label_map is None:
self.label_map = {}
for i, c in enumerate(self.CLASSES):
Expand Down
2 changes: 1 addition & 1 deletion otx/algorithms/segmentation/tasks/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(self, task_environment: TaskEnvironment, **kwargs):
self._label_dictionary = {} # type: Dict

super().__init__(SegmentationConfig, task_environment, **kwargs)
self._label_dictionary = dict(enumerate(self._labels, 1))
self._label_dictionary = dict(enumerate(sorted(self._labels), 1))

@check_input_parameters_type({"dataset": DatasetParamTypeCheck})
def infer(
Expand Down
2 changes: 2 additions & 0 deletions otx/api/usecases/evaluation/basic_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def get_intersections_and_cardinalities(
Returns:
Tuple[NumberPerLabel, NumberPerLabel]: (all_intersections, all_cardinalities)
"""

# TODO [Soobee] : Add score for background label and align the calculation method with validation
all_intersections: NumberPerLabel = {label: 0 for label in labels}
all_intersections[None] = 0
all_cardinalities: NumberPerLabel = {label: 0 for label in labels}
Expand Down