Skip to content

Commit db9125a

Browse files
stchabiSihem Tchabi
andauthored
fix(LAB-3724): fix to have all multiparts polygons when exporting ass… (#1915)
Co-authored-by: Sihem Tchabi <sihem@MacBook-Pro.local>
1 parent fccb39c commit db9125a

File tree

3 files changed

+914
-19
lines changed

3 files changed

+914
-19
lines changed

src/kili/adapters/kili_api_gateway/label/annotation_to_json_response.py

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -555,14 +555,6 @@ def _video_object_detection_annotation_to_json_response(
555555
# get the frame json response of child jobs
556556
child_jobs_frame_json_resp = json_resp_child_jobs.get(str(frame_id), {})
557557

558-
annotation_dict = {
559-
"children": child_jobs_frame_json_resp,
560-
"isKeyFrame": frame_id == key_ann_frame,
561-
"categories": [{"name": annotation["category"]}],
562-
"mid": annotation["mid"],
563-
"type": json_interface["jobs"][annotation["job"]]["tools"][0],
564-
}
565-
566558
if frame_id == key_ann_frame or next_key_ann is None:
567559
norm_vertices = key_ann["annotationValue"]["vertices"]
568560
# between two key frame annotations, an object (point, bbox, polygon) is
@@ -580,19 +572,38 @@ def _video_object_detection_annotation_to_json_response(
580572
)
581573

582574
if json_interface["jobs"][annotation["job"]]["tools"][0] == "marker":
583-
annotation_dict["point"] = norm_vertices[0][0][0]
584-
585-
elif json_interface["jobs"][annotation["job"]]["tools"][0] in {"polygon", "rectangle"}:
586-
annotation_dict["boundingPoly"] = [{"normalizedVertices": norm_vertices[0][0]}]
587-
588-
elif json_interface["jobs"][annotation["job"]]["tools"][0] == "semantic":
589-
annotation_dict["boundingPoly"] = [
590-
{"normalizedVertices": norm_vert} for norm_vert in norm_vertices[0]
575+
single_annotation = {
576+
"children": child_jobs_frame_json_resp,
577+
"isKeyFrame": frame_id == key_ann_frame,
578+
"categories": [{"name": annotation["category"]}],
579+
"mid": annotation["mid"],
580+
"type": json_interface["jobs"][annotation["job"]]["tools"][0],
581+
"point": norm_vertices[0][0][0],
582+
}
583+
json_resp[str(frame_id)].setdefault(annotation["job"], {}).setdefault(
584+
"annotations", []
585+
).append(single_annotation)
586+
587+
elif json_interface["jobs"][annotation["job"]]["tools"][0] in {
588+
"polygon",
589+
"semantic",
590+
"rectangle",
591+
}:
592+
annotations = [
593+
{
594+
"children": child_jobs_frame_json_resp,
595+
"isKeyFrame": frame_id == key_ann_frame,
596+
"categories": [{"name": annotation["category"]}],
597+
"mid": annotation["mid"],
598+
"type": json_interface["jobs"][annotation["job"]]["tools"][0],
599+
"boundingPoly": [{"normalizedVertices": ring} for ring in object_part],
600+
}
601+
for object_part in norm_vertices
591602
]
592603

593-
json_resp[str(frame_id)].setdefault(annotation["job"], {}).setdefault(
594-
"annotations", []
595-
).append(annotation_dict)
604+
json_resp[str(frame_id)].setdefault(annotation["job"], {}).setdefault(
605+
"annotations", []
606+
).extend(annotations)
596607

597608
return json_resp
598609

0 commit comments

Comments
 (0)