Skip to content

Commit a9aaea5

Browse files
committed
common.py for tests and convert platform
1 parent 163adf5 commit a9aaea5

File tree

17 files changed

+134
-132
lines changed

17 files changed

+134
-132
lines changed

superannotate/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ def consensus(*args, **kwargs):
9090
)
9191
from .input_converters.conversion import (
9292
coco_split_dataset, convert_project_type, export_annotation,
93-
import_annotation, convert_json_version
93+
import_annotation, convert_json_version, convert_platform
9494
)
95+
9596
from .old_to_new_format_convertor import update_json_format
9697
from .version import __version__
9798

superannotate/input_converters/conversion.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from .export_from_sa_conversions import export_from_sa
99
from .import_to_sa_conversions import import_to_sa
1010
from .sa_conversion import (
11-
degrade_json, sa_convert_project_type, split_coco, upgrade_json
11+
degrade_json, sa_convert_project_type, split_coco, upgrade_json, _toDesktop,
12+
_toWeb
1213
)
1314

1415
ALLOWED_TASK_TYPES = [
@@ -486,4 +487,40 @@ def convert_json_version(input_dir, output_dir, version=2):
486487
else:
487488
raise SABaseException(0, "'version' is either 1 or 2.")
488489

489-
return converted_files
490+
return converted_files
491+
492+
493+
def convert_platform(input_dir, output_dir, platform_type):
494+
"""
495+
Converts from Desktop App to Web or reverse'.
496+
497+
:param input_dir: Path to the dataset folder that you want to convert.
498+
:type input_dir: Pathlike(str or Path)
499+
:param output_dir: Path to the folder, where you want to have converted dataset.
500+
:type output_dir: Pathlike(str or Path)
501+
:param platform_type: Output platform 'Desktop' or 'Web'.
502+
:type platform_type: str
503+
504+
:return: List of converted files
505+
:rtype: list
506+
"""
507+
param_info = [
508+
(input_dir, 'input_dir', (str, Path)),
509+
(output_dir, 'output_dir', (str, Path)),
510+
(platform_type, 'platform_type', str)
511+
]
512+
for param in param_info:
513+
_type_sanity(param[0], param[1], param[2])
514+
515+
if isinstance(input_dir, str):
516+
input_dir = Path(input_dir)
517+
if isinstance(output_dir, str):
518+
output_dir = Path(output_dir)
519+
output_dir.mkdir(parents=True, exist_ok=True)
520+
521+
if platform_type == 'Web':
522+
_toWeb(input_dir, output_dir)
523+
elif platform_type == 'Desktop':
524+
_toDesktop(input_dir, output_dir)
525+
else:
526+
raise SABaseException(0, "'platform_type' is either 'Desktop' or 'Web'")

superannotate/input_converters/sa_conversion.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,3 +384,22 @@ def _degrade_json_format(new_json_path):
384384
sa_loader.append(tag)
385385

386386
return sa_loader
387+
388+
389+
def _toWeb(input_dir, output_dir):
390+
json_files = list(input_dir.glob('*.json'))
391+
for json_file in json_files:
392+
file_name = '%s___objects' % json_file.name
393+
json_data = json.load(open(json_file))
394+
json_data['comments'] = []
395+
write_to_json(output_dir / file_name, json_data)
396+
397+
398+
def _toDesktop(input_dir, output_dir):
399+
json_files = list(input_dir.glob('*.json'))
400+
401+
for json_file in json_files:
402+
file_name = str(json_file.name).replace('___objects', '')
403+
json_data = json.load(open(json_file))
404+
del json_data['comments']
405+
write_to_json(output_dir / file_name, json_data)

tests/__init__.py

Whitespace-only changes.

tests/common.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import superannotate as sa
2+
3+
4+
def upload_project(
5+
project_path,
6+
project_name,
7+
description,
8+
ptype,
9+
from_s3_bucket=None,
10+
annotation_status='NotStarted',
11+
image_quality_in_editor=None
12+
):
13+
projects = sa.search_projects(project_name, return_metadata=True)
14+
for project in projects:
15+
sa.delete_project(project)
16+
17+
project = sa.create_project(project_name, description, ptype)
18+
19+
sa.create_annotation_classes_from_classes_json(
20+
project,
21+
project_path / "classes" / "classes.json",
22+
from_s3_bucket=from_s3_bucket
23+
)
24+
sa.upload_images_from_folder_to_project(
25+
project,
26+
project_path,
27+
annotation_status=annotation_status,
28+
from_s3_bucket=from_s3_bucket,
29+
image_quality_in_editor=image_quality_in_editor
30+
)
31+
sa.upload_annotations_from_folder_to_project(
32+
project, project_path, from_s3_bucket=from_s3_bucket
33+
)
34+
35+
return project

tests/converter_test/__init__.py

Whitespace-only changes.

tests/converter_test/test_coco.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
from pathlib import Path
22

3-
import pytest
4-
53
import superannotate as sa
64

7-
8-
def upload_project(project_path, project_name, description, ptype):
9-
projects = sa.search_projects(project_name, True)
10-
if projects:
11-
sa.delete_project(projects[0])
12-
project = sa.create_project(project_name, description, ptype)
13-
14-
sa.create_annotation_classes_from_classes_json(
15-
project, project_path / "classes" / "classes.json"
16-
)
17-
sa.upload_images_from_folder_to_project(project, project_path)
18-
sa.upload_annotations_from_folder_to_project(project, project_path)
5+
from ..common import upload_project
196

207

218
def test_coco_vector_instance(tmpdir):

tests/converter_test/test_dataloop.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22

33
import superannotate as sa
44

5-
6-
def upload_project(project_path, project_name, description, ptype):
7-
projects = sa.search_projects(project_name, True)
8-
if projects:
9-
sa.delete_project(projects[0])
10-
project = sa.create_project(project_name, description, ptype)
11-
12-
sa.create_annotation_classes_from_classes_json(
13-
project, project_path / "classes" / "classes.json"
14-
)
15-
sa.upload_images_from_folder_to_project(project, project_path)
16-
sa.upload_annotations_from_folder_to_project(project, project_path)
5+
from ..common import upload_project
176

187

198
def test_dataloop_convert_vector(tmpdir):

tests/converter_test/test_googlecloud.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
from pathlib import Path
22
import superannotate as sa
3-
4-
5-
def upload_project(project_path, project_name, description, ptype):
6-
projects = sa.search_projects(project_name, True)
7-
if projects:
8-
sa.delete_project(projects[0])
9-
project = sa.create_project(project_name, description, ptype)
10-
11-
sa.create_annotation_classes_from_classes_json(
12-
project, project_path / "classes" / "classes.json"
13-
)
14-
sa.upload_images_from_folder_to_project(project, project_path)
15-
sa.upload_annotations_from_folder_to_project(project, project_path)
3+
from ..common import upload_project
164

175

186
def test_googlecloud_convert_web(tmpdir):

tests/converter_test/test_labelbox.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,7 @@
22

33
import superannotate as sa
44

5-
6-
def upload_project(project_path, project_name, description, ptype):
7-
projects = sa.search_projects(project_name, True)
8-
if projects:
9-
sa.delete_project(projects[0])
10-
project = sa.create_project(project_name, description, ptype)
11-
12-
sa.create_annotation_classes_from_classes_json(
13-
project, project_path / "classes" / "classes.json"
14-
)
15-
sa.upload_images_from_folder_to_project(project, project_path)
16-
sa.upload_annotations_from_folder_to_project(project, project_path)
5+
from ..common import upload_project
176

187

198
def test_labelbox_convert_vector(tmpdir):

0 commit comments

Comments
 (0)