Skip to content

Commit 356ae15

Browse files
authored
Merge pull request #614 from superannotateai/1970_export
Updated export_annotation
2 parents bd58bc2 + 24fb61c commit 356ae15

File tree

48 files changed

+19368
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+19368
-13
lines changed

src/superannotate/lib/app/input_converters/conversion.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
"""
22
Main module for input converters
33
"""
4+
import os
5+
import shutil
6+
import tempfile
47
from argparse import Namespace
58
from pathlib import Path
69

@@ -135,6 +138,16 @@ def _passes_converter_sanity(args, direction):
135138
)
136139

137140

141+
def change_file_extensions(directory, old_extension, new_extension):
142+
for filename in os.listdir(directory):
143+
file_path = os.path.join(directory, filename)
144+
if os.path.isfile(file_path) and filename.endswith(old_extension):
145+
if file_path.endswith(new_extension):
146+
continue
147+
new_file_path = os.path.splitext(file_path)[0] + new_extension
148+
os.rename(file_path, new_file_path)
149+
150+
138151
@Tracker
139152
def export_annotation(
140153
input_dir,
@@ -208,19 +221,28 @@ def export_annotation(
208221
),
209222
]
210223
_passes_value_sanity(values_info)
211-
212-
args = Namespace(
213-
input_dir=input_dir,
214-
output_dir=output_dir,
215-
dataset_format=dataset_format,
216-
dataset_name=dataset_name,
217-
project_type=project_type,
218-
task=task,
219-
)
220-
221-
_passes_converter_sanity(args, "export")
222-
223-
export_from_sa(args)
224+
if project_type == "Vector":
225+
extension = "___objects.json"
226+
elif project_type == "Pixel":
227+
extension = "___pixel.json"
228+
else:
229+
extension = ".json"
230+
with tempfile.TemporaryDirectory() as tmp_dir:
231+
args = Namespace(
232+
input_dir=Path(tmp_dir),
233+
output_dir=output_dir,
234+
dataset_format=dataset_format,
235+
dataset_name=dataset_name,
236+
project_type=project_type,
237+
task=task,
238+
)
239+
shutil.copytree(input_dir, tmp_dir, dirs_exist_ok=True)
240+
for _path in os.listdir(tmp_dir):
241+
if os.path.isdir(_path) and not _path.endswith("classes"):
242+
change_file_extensions(_path, ".json", extension)
243+
change_file_extensions(tmp_dir, ".json", extension)
244+
_passes_converter_sanity(args, "export")
245+
export_from_sa(args)
224246

225247

226248
@Tracker
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
import pathlib
3+
4+
5+
DATA_SET_PATH = pathlib.Path(os.getcwd()) / "data_set"
6+
7+
8+
__all__ = ["DATA_SET_PATH"]

0 commit comments

Comments
 (0)