Skip to content

Commit 6cee9e7

Browse files
committed
file metadata import
1 parent ad6209f commit 6cee9e7

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

datatorch/api/scripts/import_coco.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

134140
def 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

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
setup(
3535
name="datatorch",
36-
version="0.4.8.3",
36+
version="0.4.8.4",
3737
description="A CLI and library for interacting with DataTorch.",
3838
author="DataTorch",
3939
author_email="[email protected]",

0 commit comments

Comments
 (0)