@@ -44,6 +44,7 @@ def from_json(labeled_data, coco_output, label_format='WKT'):
4444 with open (coco_output , 'w+' ) as file_handle :
4545 file_handle .write (json .dumps (coco ))
4646
47+
4748def make_coco_metadata (project_name , created_by ):
4849 "Initializes COCO export data structure."
4950 coco = {
@@ -65,6 +66,7 @@ def make_coco_metadata(project_name, created_by):
6566
6667 return coco
6768
69+
6870def _add_label (coco , image , labels , label_format ):
6971 "Incrementally updates COCO export data structure with a new label."
7072 response = requests .get (image ['coco_url' ], stream = True )
@@ -114,23 +116,24 @@ def _add_label(coco, image, labels, label_format):
114116
115117 coco ['annotations' ].append (annotation )
116118
119+
117120def _get_polygons (label_format , label_data ):
118121 "Converts segmentation `label: String!` into polygons"
119122 if label_format == 'WKT' :
120- if isinstance (label_data , list ): # V3
123+ if isinstance (label_data , list ): # V3
121124 polygons = map (lambda x : wkt .loads (x ['geometry' ]), label_data )
122- else : # V2
125+ else : # V2
123126 polygons = wkt .loads (label_data )
124127 elif label_format == 'XY' :
125128 polygons = []
126129 for xy_list in label_data :
127- if 'geometry' in xy_list : # V3
130+ if 'geometry' in xy_list : # V3
128131 xy_list = xy_list ['geometry' ]
129132
130133 # V2 and V3
131134 assert isinstance (xy_list , list ), \
132- 'Expected list in "geometry" key but got {}' .format (xy_list )
133- else : # V2, or non-list
135+ 'Expected list in "geometry" key but got {}' .format (xy_list )
136+ else : # V2, or non-list
134137 if not isinstance (xy_list , list ) or not xy_list or 'x' not in xy_list [0 ]:
135138 # skip non xy lists
136139 continue
0 commit comments