|
1 | 1 | """Common code for the coco exporter.""" |
2 | 2 |
|
| 3 | +import json |
3 | 4 | from pathlib import Path |
4 | 5 | from typing import Dict, List, Optional |
5 | 6 |
|
@@ -69,31 +70,39 @@ def _save_assets_export( |
69 | 70 | if self.split_option == "split": |
70 | 71 | for job_name, job in self.project["jsonInterface"]["jobs"].items(): |
71 | 72 | if self._is_job_compatible(job): |
72 | | - convert_from_kili_to_coco_format( |
| 73 | + labels_json = convert_from_kili_to_coco_format( |
73 | 74 | jobs={job_name: job}, |
74 | 75 | assets=assets, |
75 | | - output_dir=Path(output_directory) / self.project["id"], |
76 | 76 | title=self.project["title"], |
77 | 77 | project_input_type=self.project["inputType"], |
78 | 78 | annotation_modifier=annotation_modifier, |
79 | 79 | merged=False, |
80 | 80 | ) |
| 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) |
81 | 87 | else: |
82 | 88 | self.logger.warning(f"Job {job_name} is not compatible with the COCO format.") |
83 | 89 | else: # merged |
84 | | - convert_from_kili_to_coco_format( |
| 90 | + labels_json = convert_from_kili_to_coco_format( |
85 | 91 | jobs={ |
86 | 92 | k: job |
87 | 93 | for k, job in self.project["jsonInterface"]["jobs"].items() |
88 | 94 | if self._is_job_compatible(job) |
89 | 95 | }, |
90 | 96 | assets=assets, |
91 | | - output_dir=Path(output_directory) / self.project["id"], |
92 | 97 | title=self.project["title"], |
93 | 98 | project_input_type=self.project["inputType"], |
94 | 99 | annotation_modifier=annotation_modifier, |
95 | 100 | merged=True, |
96 | 101 | ) |
| 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) |
97 | 106 |
|
98 | 107 | def _is_job_compatible(self, job: Job) -> bool: |
99 | 108 | if "tools" not in job: |
|
0 commit comments