Skip to content

Commit 7d1c4d4

Browse files
committed
feat(LAB-3617): handle coco export write file in the SDK
1 parent d520c63 commit 7d1c4d4

File tree

4 files changed

+784
-34
lines changed

4 files changed

+784
-34
lines changed

src/kili/services/export/format/coco/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Common code for the coco exporter."""
22

3+
import json
34
from pathlib import Path
45
from typing import Dict, List, Optional
56

@@ -69,31 +70,39 @@ def _save_assets_export(
6970
if self.split_option == "split":
7071
for job_name, job in self.project["jsonInterface"]["jobs"].items():
7172
if self._is_job_compatible(job):
72-
convert_from_kili_to_coco_format(
73+
labels_json = convert_from_kili_to_coco_format(
7374
jobs={job_name: job},
7475
assets=assets,
75-
output_dir=Path(output_directory) / self.project["id"],
7676
title=self.project["title"],
7777
project_input_type=self.project["inputType"],
7878
annotation_modifier=annotation_modifier,
7979
merged=False,
8080
)
81+
label_file_name = (
82+
Path(output_directory) / self.project["id"] / job_name / "labels.json"
83+
)
84+
label_file_name.parent.mkdir(parents=True, exist_ok=True)
85+
with label_file_name.open("w") as outfile:
86+
json.dump(labels_json, outfile)
8187
else:
8288
self.logger.warning(f"Job {job_name} is not compatible with the COCO format.")
8389
else: # merged
84-
convert_from_kili_to_coco_format(
90+
labels_json = convert_from_kili_to_coco_format(
8591
jobs={
8692
k: job
8793
for k, job in self.project["jsonInterface"]["jobs"].items()
8894
if self._is_job_compatible(job)
8995
},
9096
assets=assets,
91-
output_dir=Path(output_directory) / self.project["id"],
9297
title=self.project["title"],
9398
project_input_type=self.project["inputType"],
9499
annotation_modifier=annotation_modifier,
95100
merged=True,
96101
)
102+
label_file_name = Path(output_directory) / self.project["id"] / "labels.json"
103+
label_file_name.parent.mkdir(parents=True, exist_ok=True)
104+
with label_file_name.open("w") as outfile:
105+
json.dump(labels_json, outfile)
97106

98107
def _is_job_compatible(self, job: Job) -> bool:
99108
if "tools" not in job:

tests/unit/adapters/kili_api_gateway/label/test_label_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
_interpolate_rectangle,
88
_video_annotations_to_json_response,
99
)
10+
from kili_formats.types import ClassicAnnotation, VideoAnnotation
1011

11-
from kili.domain.annotation import ClassicAnnotation, Vertice, VideoAnnotation
12+
from kili.domain.annotation import Vertice
1213

1314
from .test_data import (
1415
test_case_1,

0 commit comments

Comments
 (0)