2020 make_keypoint ,
2121 make_line ,
2222 make_polygon ,
23+ make_tag ,
2324)
2425from darwin .importer .formats .superannotate_schemas import (
2526 classes_export ,
@@ -41,12 +42,15 @@ def parse_path(path: Path) -> Optional[AnnotationFile]:
4142 {
4243 "instances": [
4344 {
45+ "classId": 1,
46+ "attributes": [],
4447 "type": "point",
4548 "x": 1,
4649 "y": 0
4750 },
4851 // { ... }
4952 ],
53+ "tags": ["a_tag_here"],
5054 "metadata": {
5155 "name": "a_file_name.json"
5256 }
@@ -60,13 +64,14 @@ def parse_path(path: Path) -> Optional[AnnotationFile]:
6064 - bbox ``Vector`` (not rotated): https://doc.superannotate.com/docs/vector-json#bounding-box-and-rotated-bounding-box
6165 - polygon and polyline ``Vector``s: https://doc.superannotate.com/docs/vector-json#polyline-and-polygon
6266
67+ We also support attributes and tags.
6368
6469 Each file must also have in the same folder a ``classes.json`` file with information about
6570 the classes. This file must have a structure simillar to:
6671
6772 .. code-block:: javascript
6873 [
69- {"name": "a_name_here", "id": 1},
74+ {"name": "a_name_here", "id": 1, "attribute_groups": [] },
7075 // { ... }
7176 ]
7277
@@ -108,20 +113,24 @@ def parse_path(path: Path) -> Optional[AnnotationFile]:
108113
109114 instances : List [Dict [str , Any ]] = data .get ("instances" )
110115 metadata : Dict [str , Any ] = data .get ("metadata" )
116+ tags : List [str ] = data .get ("tags" )
111117
112- return _convert (instances , path , classes , metadata )
118+ return _convert (instances , path , classes , metadata , tags )
113119
114120
115121def _convert (
116122 instances : List [Dict [str , Any ]],
117123 annotation_file_path : Path ,
118124 superannotate_classes : List [Dict [str , Any ]],
119125 metadata : Dict [str , Any ],
126+ tags : List [str ],
120127) -> AnnotationFile :
121- filename : str = str ( metadata . get ( "name" ) )
128+ conver_to_darwin_object = partial ( _convert_instance , superannotate_classes = superannotate_classes )
122129
123- convert_with_classes = partial (_convert_objects , superannotate_classes = superannotate_classes )
124- annotations : List [Annotation ] = _map_to_list (convert_with_classes , instances )
130+ filename : str = str (metadata .get ("name" ))
131+ darwin_tags : List [Annotation ] = _map_to_list (_convert_tag , tags )
132+ darwin_objects : List [Annotation ] = _map_to_list (conver_to_darwin_object , instances )
133+ annotations : List [Annotation ] = darwin_objects + darwin_tags
125134 classes : Set [AnnotationClass ] = _map_to_set (_get_class , annotations )
126135
127136 return AnnotationFile (
@@ -133,7 +142,7 @@ def _convert(
133142 )
134143
135144
136- def _convert_objects (obj : Dict [str , Any ], superannotate_classes : List [Dict [str , Any ]]) -> Annotation :
145+ def _convert_instance (obj : Dict [str , Any ], superannotate_classes : List [Dict [str , Any ]]) -> Annotation :
137146 type : str = str (obj .get ("type" ))
138147
139148 if type == "point" :
@@ -157,6 +166,10 @@ def _convert_objects(obj: Dict[str, Any], superannotate_classes: List[Dict[str,
157166 raise ValueError (f"Unknown label object { obj } " )
158167
159168
169+ def _convert_tag (tag : str ) -> Annotation :
170+ return make_tag (tag )
171+
172+
160173def _to_keypoint_annotation (point : Dict [str , Any ], classes : List [Dict [str , Any ]]) -> Annotation :
161174 x : float = cast (float , point .get ("x" ))
162175 y : float = cast (float , point .get ("y" ))
0 commit comments