1515import numpy as np
1616import requests
1717
18- from fastlabel .const import AnnotationType
18+ from fastlabel .const import AnnotationType , AttributeValue
1919from fastlabel .exceptions import FastLabelInvalidException
2020from fastlabel .utils import is_video_project_type
2121
@@ -74,6 +74,9 @@ def get_annotation_points(anno, _):
7474 "annotation_type" : annotation ["type" ],
7575 "annotation_points" : get_annotation_points (annotation , index ),
7676 "annotation_keypoints" : annotation .get ("keypoints" ),
77+ "annotation_attributes" : _get_coco_annotation_attributes (
78+ annotation
79+ ),
7780 "categories" : categories ,
7881 "image_id" : task_image ["id" ],
7982 }
@@ -204,6 +207,7 @@ def __to_coco_annotation(data: dict) -> dict:
204207 annotation_type = data ["annotation_type" ]
205208 annotation_value = data ["annotation_value" ]
206209 annotation_id = 0
210+ annotation_attributes = data ["annotation_attributes" ]
207211
208212 if annotation_type not in [
209213 AnnotationType .bbox .value ,
@@ -226,7 +230,13 @@ def __to_coco_annotation(data: dict) -> dict:
226230 return None
227231
228232 return __get_coco_annotation (
229- annotation_id , points , keypoints , category ["id" ], image_id , annotation_type
233+ annotation_id ,
234+ points ,
235+ keypoints ,
236+ category ["id" ],
237+ image_id ,
238+ annotation_type ,
239+ annotation_attributes ,
230240 )
231241
232242
@@ -259,6 +269,7 @@ def __get_coco_annotation(
259269 category_id : int ,
260270 image_id : str ,
261271 annotation_type : str ,
272+ annotation_attributes : dict [str , AttributeValue ],
262273) -> dict :
263274 annotation = {}
264275 annotation ["num_keypoints" ] = len (keypoints ) if keypoints else 0
@@ -272,6 +283,7 @@ def __get_coco_annotation(
272283 annotation ["bbox" ] = __to_bbox (annotation_type , points )
273284 annotation ["category_id" ] = category_id
274285 annotation ["id" ] = id_
286+ annotation ["attributes" ] = annotation_attributes
275287 return annotation
276288
277289
@@ -848,6 +860,11 @@ def execute_coco_to_fastlabel(coco: dict, annotation_type: str) -> dict:
848860
849861 annotations = []
850862 for target_coco_annotation in target_coco_annotations :
863+ attributes_items = target_coco_annotation .get ("attributes" , {})
864+ attributes = [
865+ {"key" : attribute_key , "value" : attribute_value }
866+ for attribute_key , attribute_value in attributes_items .items ()
867+ ]
851868 category_name = coco_categories [target_coco_annotation ["category_id" ]]
852869 if not category_name :
853870 return
@@ -867,6 +884,7 @@ def execute_coco_to_fastlabel(coco: dict, annotation_type: str) -> dict:
867884 "value" : category_name ,
868885 "points" : segmentation ,
869886 "type" : annotation_type ,
887+ "attributes" : attributes ,
870888 }
871889 )
872890 elif annotation_type == AnnotationType .pose_estimation .value :
@@ -898,6 +916,7 @@ def execute_coco_to_fastlabel(coco: dict, annotation_type: str) -> dict:
898916 "value" : category_name ,
899917 "type" : annotation_type ,
900918 "keypoints" : keypoints ,
919+ "attributes" : attributes ,
901920 }
902921 )
903922 else :
@@ -1107,3 +1126,13 @@ def _get_annotation_points_for_video_annotation(annotation: dict, index: int):
11071126
11081127def _get_annotation_points_for_image_annotation (annotation : dict ):
11091128 return annotation .get ("points" )
1129+
1130+
1131+ def _get_coco_annotation_attributes (annotation : dict ) -> dict [str , AttributeValue ]:
1132+ coco_attributes = {}
1133+ attributes = annotation .get ("attributes" )
1134+ if not attributes :
1135+ return coco_attributes
1136+ for attribute in attributes :
1137+ coco_attributes [attribute ["key" ]] = attribute ["value" ]
1138+ return coco_attributes
0 commit comments