Skip to content

Commit

Permalink
Add circumvention for multiple annots & bad labs
Browse files Browse the repository at this point in the history
See FRML-128 issue for more details on this fix
  • Loading branch information
Eve-ning committed Mar 25, 2024
1 parent c89c1a0 commit 3709485
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions src/frdc/load/label_studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,42 @@ class Task(dict):
def get_bounds_and_labels(self) -> tuple[list[tuple[int, int]], list[str]]:
bounds = []
labels = []
for ann_ix, ann in enumerate(self["annotations"]):
results = ann["result"]
for r_ix, r in enumerate(results):
r: dict

# We flatten the value dict into the result dict
v = r.pop("value")
r = {**r, **v}

# Points are in percentage, we need to convert them to pixels
r["points"] = [
(
int(x * r["original_width"] / 100),
int(y * r["original_height"] / 100),
)
for x, y in r["points"]
]

# Only take the first label as this is not a multi-label task
r["label"] = r.pop("polygonlabels")[0]
if not r["closed"]:
logger.warning(
f"Label for {r['label']} @ {r['points']} not closed. "
f"Skipping"
)
continue

bounds.append(r["points"])
labels.append(r["label"])

# for ann_ix, ann in enumerate(self["annotations"]):

ann = self["annotations"][0]
results = ann["result"]
for r_ix, r in enumerate(results):
r: dict

# See Issue FRML-78: Somehow some labels are actually just metadata
if r["from_name"] != "label":
continue

# We flatten the value dict into the result dict
v = r.pop("value")
r = {**r, **v}

# Points are in percentage, we need to convert them to pixels
r["points"] = [
(
int(x * r["original_width"] / 100),
int(y * r["original_height"] / 100),
)
for x, y in r["points"]
]

# Only take the first label as this is not a multi-label task
r["label"] = r.pop("polygonlabels")[0]
if not r["closed"]:
logger.warning(
f"Label for {r['label']} @ {r['points']} not closed. "
f"Skipping"
)
continue

bounds.append(r["points"])
labels.append(r["label"])

return bounds, labels

Expand Down

0 comments on commit 3709485

Please sign in to comment.