@@ -130,6 +130,12 @@ def simplify_segmentation(segmentation: List[List[float]], tolerance: float = 1)
130130 }
131131"""
132132
133+ _SET_FILE_METADATA = """
134+ mutation SetFileMetadata($fileId: ID!, $key: String!, $value: JSON!) {
135+ setFileMetadata(fileId: $fileId, key: $key, value: $value)
136+ }
137+ """
138+
133139
134140def import_coco (
135141 file_path : str ,
@@ -141,6 +147,8 @@ def import_coco(
141147 simplify_tolerance : float = 0 ,
142148 ignore_annotations_with_ids : bool = True ,
143149 api : ApiClient = None ,
150+ upload_file_metadata : bool = False ,
151+ upload_anno_metadata : bool = False ,
144152):
145153 if not import_segmentation and not import_bbox :
146154 _LOGGER .warning ("Nothing to import. Both segmentation and bbox are disabled." )
@@ -219,6 +227,16 @@ def import_coco(
219227 )
220228 continue
221229
230+ # Upload file metadata if they want to
231+ if upload_file_metadata :
232+ file_metadata = coco_image .get ("metadata" , {})
233+ if len (file_metadata ) > 0 :
234+ for key , value in file_metadata .items ():
235+ api .execute (
236+ _SET_FILE_METADATA ,
237+ params = {"fileId" : dt_file .id , "key" : key , "value" : value },
238+ )
239+
222240 coco_annotation_ids = coco .getAnnIds (
223241 catIds = coco_category_ids , imgIds = coco_image ["id" ]
224242 )
@@ -311,6 +329,14 @@ def import_coco(
311329 }
312330 )
313331
332+ # Metadata stuff
333+ # need to upload the create annotations api first
334+ # metadata = anno.get("metadata", {})
335+ # for metadata_key, metadata_value in metadata.items():
336+ # print(metadata)
337+ # print(metadata_key)
338+ # print(metadata_value)
339+
314340 if created_segmentation or created_bbox :
315341 new_annotations .append (annotation )
316342
0 commit comments