Skip to content

Commit 6bab737

Browse files
committed
Init metadata with width and height
1 parent 2b0a820 commit 6bab737

File tree

7 files changed

+63
-17
lines changed

7 files changed

+63
-17
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
],
88
"python.testing.unittestEnabled": false,
99
"python.testing.nosetestsEnabled": false,
10-
"python.testing.pytestEnabled": true
10+
"python.testing.pytestEnabled": true,
11+
"python.pythonPath": "venv_sa_conv/bin/python"
1112
}

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ dist:
4444
twine upload dist/*
4545

4646
check_formatting:
47-
yapf -p -r --diff -e '*/pycocotools_sa' superannotate
47+
yapf -p -r --diff superannotate

superannotate/db/annotation_classes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ def download_annotation_classes_json(project, folder):
296296

297297

298298
def fill_class_and_attribute_names(annotations_json, annotation_classes_dict):
299+
if "instances" not in annotations_json:
300+
return
299301
for r in annotations_json["instances"]:
300302
if "classId" in r and r["classId"] in annotation_classes_dict:
301303
r["className"] = annotation_classes_dict[r["classId"]]["name"]

superannotate/db/project_images.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def upload_image_to_project(
114114
images_array = get_image_array_to_upload(
115115
img, image_quality_in_editor, project["type"]
116116
)
117-
upload_image_array_to_s3(bucket, *images_array, key)
117+
upload_image_array_to_s3(bucket, *images_array, key, project["type"])
118118
except Exception as e:
119119
raise SABaseException(0, "Couldn't upload to data server. " + e)
120120

superannotate/db/projects.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,13 @@ def upload_images_from_folder_to_project(
538538
)
539539

540540

541+
def create_empty_annotation(size):
542+
return {"metadata": {'height': size[1], 'width': size[0]}}
543+
544+
541545
def upload_image_array_to_s3(
542-
bucket, size, orig_image, lores_image, huge_image, thumbnail_image, key
546+
bucket, size, orig_image, lores_image, huge_image, thumbnail_image, key,
547+
project_type
543548
):
544549
bucket.put_object(Body=orig_image, Key=key)
545550
bucket.put_object(Body=lores_image, Key=key + '___lores.jpg')
@@ -552,6 +557,10 @@ def upload_image_array_to_s3(
552557
}
553558
)
554559
bucket.put_object(Body=thumbnail_image, Key=key + '___thumb.jpg')
560+
postfix_json = '___objects.json' if project_type == "Vector" else '___pixel.json'
561+
bucket.put_object(
562+
Body=json.dumps(create_empty_annotation(size)), Key=key + postfix_json
563+
)
555564

556565

557566
def get_image_array_to_upload(
@@ -657,7 +666,9 @@ def __upload_images_to_aws_thread(
657666
images_array = get_image_array_to_upload(
658667
file, image_quality_in_editor, project["type"]
659668
)
660-
upload_image_array_to_s3(bucket, *images_array, key)
669+
upload_image_array_to_s3(
670+
bucket, *images_array, key, project["type"]
671+
)
661672
except Exception as e:
662673
logger.warning("Unable to upload image %s. %s", path, e)
663674
couldnt_upload[thread_id].append(path)
@@ -1191,8 +1202,8 @@ def upload_annotations_from_folder_to_project(
11911202
:param recursive_subfolders: enable recursive subfolder parsing
11921203
:type recursive_subfolders: bool
11931204
1194-
:return: paths to annotations uploaded
1195-
:rtype: list of strs
1205+
:return: paths to annotations uploaded, could-not-upload, missing-images
1206+
:rtype: tuple of list of strs
11961207
"""
11971208
if recursive_subfolders:
11981209
logger.info(
@@ -1439,6 +1450,7 @@ def __tqdm_thread_upload_annotations(
14391450
pbar.update(total_num - pbar.n)
14401451
break
14411452

1453+
14421454
def __tqdm_thread_upload_preannotations(
14431455
total_num, uploaded, couldnt_upload, finish_event
14441456
):
@@ -1480,8 +1492,8 @@ def upload_preannotations_from_folder_to_project(
14801492
:param recursive_subfolders: enable recursive subfolder parsing
14811493
:type recursive_subfolders: bool
14821494
1483-
:return: paths to pre-annotations uploaded
1484-
:rtype: list of strs
1495+
:return: paths to pre-annotations uploaded and could-not-upload
1496+
:rtype: tuple of list of strs
14851497
"""
14861498
if recursive_subfolders:
14871499
logger.info(
@@ -1583,7 +1595,6 @@ def _upload_preannotations_from_folder_to_project(
15831595
finish_event = threading.Event()
15841596
tqdm_thread = threading.Thread(
15851597
target=__tqdm_thread_upload_preannotations,
1586-
15871598
args=(len_preannotations_paths, couldnt_upload, uploaded, finish_event),
15881599
daemon=True
15891600
)
@@ -1627,7 +1638,6 @@ def _upload_preannotations_from_folder_to_project(
16271638
for file in upload_thread:
16281639
list_of_uploaded.append(str(file))
16291640
return (list_of_uploaded, list_of_not_uploaded)
1630-
return return_result + [str(p) for p in preannotations_paths]
16311641

16321642

16331643
def share_project(project, user, user_role):

tests/test_init_annot.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pathlib import Path
2+
3+
import cv2
4+
5+
import superannotate as sa
6+
7+
name = "Example Project test meta init"
8+
project_type = "Vector"
9+
description = "test vector"
10+
from_folder = Path("./tests/sample_project_vector_for_checks")
11+
12+
13+
def test_meta_init(tmpdir):
14+
projects = sa.search_projects(name, return_metadata=True)
15+
for project in projects:
16+
sa.delete_project(project)
17+
18+
project = sa.create_project(name, description, project_type)
19+
20+
sa.upload_images_from_folder_to_project(
21+
project, from_folder, annotation_status="NotStarted"
22+
)
23+
24+
for image in from_folder.glob("*.jpg"):
25+
size = cv2.imread(str(image)).shape
26+
annot = sa.get_image_annotations(project, image.name)["annotation_json"]
27+
print(annot)
28+
assert annot["metadata"]["width"] == size[1]
29+
assert annot["metadata"]["height"] == size[0]

tests/test_missing_annotation_upload.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import superannotate as sa
44

5-
name = "Example Project test vector missing annotation upload"
6-
project_type = "Vector"
7-
description = "test vector"
8-
from_folder = Path("./tests/sample_project_vector_for_checks")
9-
10-
115
def test_missing_annotation_upload(tmpdir):
6+
name = "Example Project test vector missing annotation upload"
7+
project_type = "Vector"
8+
description = "test vector"
9+
from_folder = Path("./tests/sample_project_vector_for_checks")
1210
projects = sa.search_projects(name, return_metadata=True)
1311
for project in projects:
1412
sa.delete_project(project)
@@ -44,6 +42,12 @@ def test_missing_annotation_upload(tmpdir):
4442

4543

4644
def test_missing_preannotation_upload(tmpdir):
45+
name = "Example Project test vector missing preannotation upload"
46+
project_type = "Vector"
47+
description = "test vector"
48+
from_folder = Path("./tests/sample_project_vector_for_checks")
49+
50+
4751
projects = sa.search_projects(name, return_metadata=True)
4852
for project in projects:
4953
sa.delete_project(project)

0 commit comments

Comments
 (0)