Skip to content

Commit

Permalink
refactor(dataset): simplify extract_labels
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Nov 13, 2024
1 parent e18d769 commit cd0123c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/nrtk_explorer/library/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,14 @@ def extract_labels(feature):
if isinstance(feature, list):
return extract_labels(feature[0])
if isinstance(feature, dict):
for key in ["category", "category_id", "label"]:
for key in ["category", "category_id", "label", "labels", "objects"]:
if key in feature:
return extract_labels(feature[key])
labels = extract_labels(feature[key])
if labels:
return labels
return None

features = self._dataset.features
labels = None
if "labels" in features:
labels = extract_labels(features["labels"])
if not labels and "objects" in features:
labels = extract_labels(features["objects"])
labels = extract_labels(self._dataset.features)
if labels:
self.cats = {i: {"id": i, "name": str(name)} for i, name in enumerate(labels)}

Expand Down

0 comments on commit cd0123c

Please sign in to comment.