1+ import glob
12import json
23import logging
34from pathlib import Path
4- import glob
55
66import pandas as pd
7+
78from ..exceptions import SABaseException
9+
810logger = logging .getLogger ("superannotate-python-sdk" )
911
1012
@@ -29,7 +31,12 @@ def df_to_annotations(df, output_dir):
2931 image_height = None
3032 image_width = None
3133 image_df = df [df ["imageName" ] == image ]
32- image_annotation = []
34+ image_annotation = {
35+ "instances" : [],
36+ "metadata" : {},
37+ "tags" : [],
38+ "comments" : []
39+ }
3340 instances = image_df ["instanceId" ].dropna ().unique ()
3441 for instance in instances :
3542 instance_df = image_df [image_df ["instanceId" ] == instance ]
@@ -64,27 +71,31 @@ def df_to_annotations(df, output_dir):
6471 "name" : row ["attributeName" ]
6572 }
6673 )
67- image_annotation .append (instance_annotation )
74+ image_annotation [ "instances" ] .append (instance_annotation )
6875 image_width = image_width or instance_df .iloc [0 ]["imageWidth" ]
6976 image_height = image_height or instance_df .iloc [0 ]["imageHeight" ]
7077 image_pinned = image_pinned or instance_df .iloc [0 ]["imagePinned" ]
7178 image_status = image_status or instance_df .iloc [0 ]["imageStatus" ]
7279
7380 comments = image_df [image_df ["type" ] == "comment" ]
7481 for _ , comment in comments .iterrows ():
75- comment_json = {"type" : "comment" }
82+ comment_json = {}
7683 comment_json .update (comment ["meta" ])
84+ comment_json ["correspondence" ] = comment_json ["comments" ]
85+ del comment_json ["comments" ]
7786 comment_json ["resolved" ] = comment ["commentResolved" ]
78- image_annotation .append (comment_json )
87+ image_annotation [ "comments" ] .append (comment_json )
7988
80- meta = {
81- "type" : "meta" ,
89+ tags = image_df [image_df ["type" ] == "tag" ]
90+ for _ , tag in tags .iterrows ():
91+ image_annotation ["tags" ].append (tag ["tag" ])
92+
93+ image_annotation ["metadata" ] = {
8294 "width" : int (image_width ),
8395 "height" : int (image_height ),
8496 "status" : image_status ,
8597 "pinned" : bool (image_pinned )
8698 }
87- image_annotation .append (meta )
8899 json .dump (
89100 image_annotation ,
90101 open (output_dir / f"{ image } ___{ project_suffix } " , "w" ),
@@ -281,10 +292,10 @@ def __get_user_metadata(annotation):
281292 comment_meta = {
282293 "x" : annotation ["x" ],
283294 "y" : annotation ["y" ],
284- "comments" : annotation ["comments " ]
295+ "comments" : annotation ["correspondence " ]
285296 }
286297 annotation_dict = {
287- "type" : annotation_type ,
298+ "type" : "comment" ,
288299 "meta" : comment_meta ,
289300 "commentResolved" : comment_resolved ,
290301 }
@@ -294,11 +305,7 @@ def __get_user_metadata(annotation):
294305 __append_annotation (annotation_dict )
295306 if include_tags :
296307 for annotation in annotation_json ["tags" ]:
297- annotation_tag = annotation ["name" ]
298- annotation_dict = {
299- "type" : annotation_type ,
300- "tag" : annotation_tag
301- }
308+ annotation_dict = {"type" : "tag" , "tag" : annotation }
302309 annotation_dict .update (image_metadata )
303310 __append_annotation (annotation_dict )
304311 for annotation in annotation_json ["instances" ]:
0 commit comments