Skip to content

Commit

Permalink
Add dumping hierarchical information to M-API config (openvinotoolkit…
Browse files Browse the repository at this point in the history
…#2136)

Add dumping hierarchical information to mapi config
  • Loading branch information
sovrasov committed May 15, 2023
1 parent fcd3ecd commit 66c1e2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion otx/algorithms/classification/utils/cls_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# pylint: disable=too-many-nested-blocks, invalid-name

import json
from operator import itemgetter
from typing import Any, Dict

Expand Down Expand Up @@ -103,6 +104,13 @@ def get_cls_model_api_configuration(label_schema: LabelSchemaEntity, inference_c
for lbl in label_schema.get_labels(include_empty=False):
all_labels += lbl.name.replace(" ", "_") + " "
all_labels = all_labels.strip()

mapi_config[("model_info", "labels")] = all_labels

hierarchical_config = {}
hierarchical_config["cls_heads_info"] = get_multihead_class_info(label_schema)
hierarchical_config["label_tree_edges"] = []
for edge in label_schema.label_tree.edges: # (child, parent)
hierarchical_config["label_tree_edges"].append((edge[0].name.replace(" ", "_"), edge[1].name.replace(" ", "_")))

mapi_config[("model_info", "hierarchical_config")] = json.dumps(hierarchical_config)
return mapi_config
3 changes: 2 additions & 1 deletion tests/unit/algorithms/classification/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ def test_get_cls_model_api_configuration(default_hierarchical_data):
model_api_cfg = get_cls_model_api_configuration(label_schema, config)

assert len(model_api_cfg) > 0
model_api_cfg[("model_info", "confidence_threshold")] = str(config["confidence_threshold"])
assert model_api_cfg[("model_info", "confidence_threshold")] == str(config["confidence_threshold"])
assert ("model_info", "hierarchical_config") in model_api_cfg

0 comments on commit 66c1e2a

Please sign in to comment.