Skip to content

Commit

Permalink
Don't apply labels normalization on training (#3886)
Browse files Browse the repository at this point in the history
* Don't apply labels normalization on training

* Fix black
  • Loading branch information
sovrasov authored Aug 26, 2024
1 parent ab54588 commit f2d5476
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/otx/algorithms/classification/utils/cls_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@
from otx.api.utils.labels_utils import get_normalized_label_name


def get_multihead_class_info(label_schema: LabelSchemaEntity): # pylint: disable=too-many-locals
def get_multihead_class_info(
label_schema: LabelSchemaEntity, normalize_labels: bool = False
): # pylint: disable=too-many-locals
"""Get multihead info by label schema."""
all_groups = label_schema.get_groups(include_empty=False)
all_groups_str = []
for g in all_groups:
group_labels_str = [get_normalized_label_name(lbl) for lbl in g.labels]
if normalize_labels:
group_labels_str = [get_normalized_label_name(lbl) for lbl in g.labels]
else:
group_labels_str = [lbl.name for lbl in g.labels]
all_groups_str.append(group_labels_str)

single_label_groups = [g for g in all_groups_str if len(g) == 1]
Expand Down Expand Up @@ -77,7 +82,7 @@ def get_cls_inferencer_configuration(label_schema: LabelSchemaEntity):
hierarchical = not multilabel and len(label_schema.get_groups(False)) > 1
multihead_class_info = {}
if hierarchical:
multihead_class_info = get_multihead_class_info(label_schema)
multihead_class_info = get_multihead_class_info(label_schema, normalize_labels=True)
return {
"multilabel": multilabel,
"hierarchical": hierarchical,
Expand Down Expand Up @@ -120,7 +125,7 @@ def get_cls_model_api_configuration(label_schema: LabelSchemaEntity, inference_c
mapi_config[("model_info", "label_ids")] = all_label_ids.strip()

hierarchical_config = {}
hierarchical_config["cls_heads_info"] = get_multihead_class_info(label_schema)
hierarchical_config["cls_heads_info"] = get_multihead_class_info(label_schema, normalize_labels=True)
hierarchical_config["label_tree_edges"] = []
for edge in label_schema.label_tree.edges: # (child, parent)
hierarchical_config["label_tree_edges"].append(
Expand Down

0 comments on commit f2d5476

Please sign in to comment.