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

Add greedy labels resolver #2064

Merged
merged 5 commits into from
May 10, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix grammar
sovrasov committed May 9, 2023
commit d893ba37bbe36617f5e95d77c8f10d78283df57e
4 changes: 2 additions & 2 deletions otx/api/entities/label_schema.py
Original file line number Diff line number Diff line change
@@ -558,12 +558,12 @@ def from_labels(cls, labels: Sequence[LabelEntity]) -> "LabelSchemaEntity":
label_group = LabelGroup(name="from_label_list", labels=labels)
return LabelSchemaEntity(label_groups=[label_group])

def resolve_labels_greedy(self, scored_labels: List[ScoredLabel]) -> List[ScoredLabel]:
def resolve_labels_greedily(self, scored_labels: List[ScoredLabel]) -> List[ScoredLabel]:
"""Resolves hierarchical labels and exclusivity based on a list of ScoredLabels (labels with probability).

The following two steps are taken:

- selects the most likely label from each label group
- select the most likely label from each label group
- add their predecessors if they are also most likely labels (greedy approach).
sovrasov marked this conversation as resolved.
Show resolved Hide resolved

Args:
6 changes: 3 additions & 3 deletions tests/unit/api/entities/test_label_schema.py
Original file line number Diff line number Diff line change
@@ -1845,7 +1845,7 @@ def test_label_schema_resolve_labels(self):
]
assert ref_labels == resloved_labels

resloved_labels_greedy = label_schema.resolve_labels_greedy(predicted_labels)
resloved_labels_greedy = label_schema.resolve_labels_greedily(predicted_labels)
assert ref_labels == resloved_labels_greedy

# supress children of non-maximum labels
@@ -1858,7 +1858,7 @@ def test_label_schema_resolve_labels(self):
ref_labels = [ScoredLabel(labels_2[1], 0.5)]
assert ref_labels == resloved_labels

resloved_labels_greedy = label_schema.resolve_labels_greedy(predicted_labels)
resloved_labels_greedy = label_schema.resolve_labels_greedily(predicted_labels)
assert ref_labels == resloved_labels_greedy

@pytest.mark.reqids(Requirements.REQ_1)
@@ -1913,4 +1913,4 @@ def test_label_schema_resolve_labels_greedy(self):
ScoredLabel(g4_labels[0], 0.9),
]

assert ref_labels == label_schema.resolve_labels_greedy(predicted_labels)
assert ref_labels == label_schema.resolve_labels_greedily(predicted_labels)