Skip to content

Commit 163adf5

Browse files
committed
2 parents 48bfa06 + 548107e commit 163adf5

17 files changed

+9769
-82
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
348348
del attribute["groupId"]
349349

350350

351+
def check_annotation_json(annotation_json):
352+
if "metadata" not in annotation_json or "width" not in annotation_json[
353+
"metadata"] or "height" not in annotation_json["metadata"]:
354+
return False
355+
else:
356+
return True
357+
358+
351359
def get_annotation_classes_id_to_name(annotation_classes):
352360
annotation_classes_dict = {}
353361
for annotation_class in annotation_classes:

superannotate/db/images.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -753,13 +753,17 @@ def get_image_annotations(project, image_name, project_type=None):
753753
raise SABaseException(response.status_code, response.text)
754754
res_json = response.json()
755755
fill_class_and_attribute_names(res_json, annotation_classes_dict)
756-
url = res["pixelSave"]["url"]
757-
annotation_mask_filename = url.rsplit('/', 1)[-1]
758-
headers = res["pixelSave"]["headers"]
759-
response = requests.get(url=url, headers=headers)
760-
if not response.ok:
761-
raise SABaseException(response.status_code, response.text)
762-
mask = io.BytesIO(response.content)
756+
if len(res_json["instances"]) != 0:
757+
url = res["pixelSave"]["url"]
758+
annotation_mask_filename = url.rsplit('/', 1)[-1]
759+
headers = res["pixelSave"]["headers"]
760+
response = requests.get(url=url, headers=headers)
761+
if not response.ok:
762+
raise SABaseException(response.status_code, response.text)
763+
mask = io.BytesIO(response.content)
764+
else:
765+
mask = None
766+
annotation_mask_filename = None
763767
return {
764768
"annotation_json": res_json,
765769
"annotation_json_filename": annotation_json_filename,
@@ -800,11 +804,14 @@ def download_image_annotations(project, image_name, local_dir_path):
800804
else:
801805
with open(json_path, "w") as f:
802806
json.dump(annotation["annotation_json"], f, indent=4)
803-
mask_path = Path(local_dir_path
804-
) / annotation["annotation_mask_filename"]
807+
if annotation["annotation_mask_filename"] is not None:
808+
mask_path = Path(local_dir_path
809+
) / annotation["annotation_mask_filename"]
810+
with open(mask_path, "wb") as f:
811+
f.write(annotation["annotation_mask"].getbuffer())
812+
else:
813+
mask_path = None
805814
return_filepaths.append(str(mask_path))
806-
with open(mask_path, "wb") as f:
807-
f.write(annotation["annotation_mask"].getbuffer())
808815

809816
return tuple(return_filepaths)
810817

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

0 commit comments

Comments
 (0)