@@ -130,6 +130,12 @@ def simplify_segmentation(segmentation: List[List[float]], tolerance: float = 1)
130
130
}
131
131
"""
132
132
133
+ _SET_FILE_METADATA = """
134
+ mutation SetFileMetadata($fileId: ID!, $key: String!, $value: JSON!) {
135
+ setFileMetadata(fileId: $fileId, key: $key, value: $value)
136
+ }
137
+ """
138
+
133
139
134
140
def import_coco (
135
141
file_path : str ,
@@ -141,6 +147,8 @@ def import_coco(
141
147
simplify_tolerance : float = 0 ,
142
148
ignore_annotations_with_ids : bool = True ,
143
149
api : ApiClient = None ,
150
+ upload_file_metadata : bool = False ,
151
+ upload_anno_metadata : bool = False ,
144
152
):
145
153
if not import_segmentation and not import_bbox :
146
154
_LOGGER .warning ("Nothing to import. Both segmentation and bbox are disabled." )
@@ -219,6 +227,16 @@ def import_coco(
219
227
)
220
228
continue
221
229
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
+
222
240
coco_annotation_ids = coco .getAnnIds (
223
241
catIds = coco_category_ids , imgIds = coco_image ["id" ]
224
242
)
@@ -311,6 +329,14 @@ def import_coco(
311
329
}
312
330
)
313
331
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
+
314
340
if created_segmentation or created_bbox :
315
341
new_annotations .append (annotation )
316
342
0 commit comments