Skip to content

Commit

Permalink
Consider multilabel scenario in h-cls
Browse files Browse the repository at this point in the history
  • Loading branch information
sovrasov committed Nov 26, 2024
1 parent 52fdb8d commit a7a082e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/otx/core/data/dataset/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,22 @@ def _get_item_impl(self, index: int) -> HlabelClsDataEntity | None:
ignored_labels: list[int] = [] # This should be assigned form item
img_data, img_shape, _ = self._get_img_data_and_shape(img)

label_anns = []
label_ids = set()
for ann in item.annotations:
# in h-cls scenario multilabel information stored in 'multi_label_ids' attribute
if "multi_label_ids" in ann.attributes:
for lbl_idx in ann.attributes["multi_label_ids"]:
label_ids.add(lbl_idx)

Check warning on line 215 in src/otx/core/data/dataset/classification.py

View check run for this annotation

Codecov / codecov/patch

src/otx/core/data/dataset/classification.py#L214-L215

Added lines #L214 - L215 were not covered by tests

if isinstance(ann, Label):
label_anns.append(ann)
label_ids.add(ann.label)
else:
# If the annotation is not Label, it should be converted to Label.
# For Chained Task: Detection (Bbox) -> Classification (Label)
label = Label(label=ann.label)
if label not in label_anns:
label_anns.append(label)
hlabel_labels = self._convert_label_to_hlabel_format(label_anns, ignored_labels)
label_ids.add(label.label)

hlabel_labels = self._convert_label_to_hlabel_format([Label(label=idx) for idx in label_ids], ignored_labels)

entity = HlabelClsDataEntity(
image=img_data,
Expand Down

0 comments on commit a7a082e

Please sign in to comment.