Skip to content

Commit de371ae

Browse files
committed
2 parents e7a57db + 56a14de commit de371ae

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ venv_*
139139
pylint.html
140140
_mask.c
141141
tags
142+
temp

superannotate/db/annotation_classes.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,25 @@ def download_annotation_classes_json(project, folder):
297297

298298
def fill_class_and_attribute_names(annotations_json, annotation_classes_dict):
299299
for r in annotations_json["instances"]:
300-
if "classId" in r and r["classId"] in annotation_classes_dict:
301-
r["className"] = annotation_classes_dict[r["classId"]]["name"]
302-
if "attributes" in r:
303-
for attribute in r["attributes"]:
304-
if "groupId" in attribute and "id" in "attribute":
305-
attribute["groupName"] = annotation_classes_dict[
306-
r["classId"]]["attribute_groups"][
307-
attribute["groupId"]]["name"]
308-
attribute["name"] = annotation_classes_dict[
309-
r["classId"]]["attribute_groups"][attribute[
310-
"groupId"]]["attributes"][attribute["id"]]
300+
if "classId" not in r or r["classId"] not in annotation_classes_dict:
301+
continue
302+
r["className"] = annotation_classes_dict[r["classId"]]["name"]
303+
if "attributes" not in r:
304+
continue
305+
for attribute in r["attributes"]:
306+
if "groupId" not in attribute or "id" not in attribute:
307+
continue
308+
if attribute["groupId"] not in annotation_classes_dict[
309+
r["classId"]]["attribute_groups"]:
310+
continue
311+
attribute["groupName"] = annotation_classes_dict[
312+
r["classId"]]["attribute_groups"][attribute["groupId"]]["name"]
313+
if attribute["id"] not in annotation_classes_dict[r["classId"]][
314+
"attribute_groups"][attribute["groupId"]]["attributes"]:
315+
continue
316+
attribute["name"] = annotation_classes_dict[
317+
r["classId"]]["attribute_groups"][
318+
attribute["groupId"]]["attributes"][attribute["id"]]
311319

312320

313321
def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
@@ -324,28 +332,27 @@ def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
324332
class_id = annotation_classes_dict[annotation_class_name]["id"]
325333
ann["classId"] = class_id
326334
for attribute in ann["attributes"]:
327-
if attribute["groupName"] in annotation_classes_dict[
335+
if attribute["groupName"] not in annotation_classes_dict[
328336
annotation_class_name]["attribute_groups"]:
329-
attribute["groupId"] = annotation_classes_dict[
330-
annotation_class_name]["attribute_groups"][
331-
attribute["groupName"]]["id"]
332-
else:
333337
logger.warning(
334338
"Couldn't find annotation group %s", attribute["groupName"]
335339
)
336340
continue
337-
if attribute["name"] in annotation_classes_dict[
341+
attribute["groupId"] = annotation_classes_dict[
342+
annotation_class_name]["attribute_groups"][
343+
attribute["groupName"]]["id"]
344+
if attribute["name"] not in annotation_classes_dict[
338345
annotation_class_name]["attribute_groups"][
339346
attribute["groupName"]]["attributes"]:
340-
attribute["id"] = annotation_classes_dict[
341-
annotation_class_name]["attribute_groups"][
342-
attribute["groupName"]]["attributes"][attribute["name"]]
343-
else:
344347
logger.warning(
345348
"Couldn't find annotation name %s in annotation group %s",
346349
attribute["name"], attribute["groupName"]
347350
)
348351
del attribute["groupId"]
352+
continue
353+
attribute["id"] = annotation_classes_dict[annotation_class_name][
354+
"attribute_groups"][attribute["groupName"]]["attributes"][
355+
attribute["name"]]
349356

350357

351358
def check_annotation_json(annotation_json):

superannotate/db/projects.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
_api = API.get_instance()
4343
_NUM_THREADS = 10
44+
_TIME_TO_UPDATE_IN_TQDM = 1
4445

4546

4647
def create_project(project_name, project_description, project_type):
@@ -1196,7 +1197,8 @@ def __upload_annotations_thread(
11961197
if not check_annotation_json(annotation_json):
11971198
couldnt_upload[thread_id].append(full_path)
11981199
logger.warning(
1199-
"Annotation JSON %s missing width or height info", full_path
1200+
"Annotation JSON %s missing width or height info. Skipping upload",
1201+
full_path
12001202
)
12011203
continue
12021204
fill_class_and_attribute_ids(
@@ -1431,7 +1433,8 @@ def __upload_preannotations_thread(
14311433
if not check_annotation_json(annotation_json):
14321434
couldnt_upload[thread_id].append(full_path)
14331435
logger.warning(
1434-
"Annotation JSON %s missing width or height info", full_path
1436+
"Annotation JSON %s missing width or height info. Skipping upload",
1437+
full_path
14351438
)
14361439
continue
14371440
fill_class_and_attribute_ids(annotation_json, annotation_classes_dict)
@@ -1460,7 +1463,7 @@ def __upload_preannotations_thread(
14601463
def __tqdm_thread_upload(total_num, uploaded, couldnt_upload, finish_event):
14611464
with tqdm(total=total_num) as pbar:
14621465
while True:
1463-
finished = finish_event.wait(5)
1466+
finished = finish_event.wait(_TIME_TO_UPDATE_IN_TQDM)
14641467
if not finished:
14651468
sum_all = 0
14661469
for i in couldnt_upload:
@@ -1478,7 +1481,7 @@ def __tqdm_thread_upload_annotations(
14781481
):
14791482
with tqdm(total=total_num) as pbar:
14801483
while True:
1481-
finished = finish_event.wait(5)
1484+
finished = finish_event.wait(_TIME_TO_UPDATE_IN_TQDM)
14821485
if not finished:
14831486
sum_all = 0
14841487
for i in couldnt_upload:
@@ -1498,7 +1501,7 @@ def __tqdm_thread_upload_preannotations(
14981501
):
14991502
with tqdm(total=total_num) as pbar:
15001503
while True:
1501-
finished = finish_event.wait(5)
1504+
finished = finish_event.wait(_TIME_TO_UPDATE_IN_TQDM)
15021505
if not finished:
15031506
sum_all = 0
15041507
for i in couldnt_upload:

superannotate/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.1.0"
1+
__version__ = "3.1.2"

tests/test_image_copy_move.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from pathlib import Path
22

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

75
PROJECT_NAME_CPY = "test image copy 1"

tests/test_single_annotation_download.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_annotation_download_upload(
4242

4343
project = upload_project(from_folder, name, description, project_type)
4444

45-
image = sa.search_images(project)[2]
45+
image = sa.search_images(project)[0]
4646
paths = sa.download_image_annotations(project, image, tmpdir)
4747

4848
input_annotation_paths_after = sa.image_path_to_annotation_paths(
@@ -68,8 +68,14 @@ def test_annotation_download_upload(
6868
json2 = json.load(open(anns_json_in_folder[0]))
6969
for i in json1["instances"]:
7070
i.pop("classId", None)
71+
for j in i["attributes"]:
72+
j.pop("groupId", None)
73+
j.pop("id", None)
7174
for i in json2["instances"]:
7275
i.pop("classId", None)
76+
for j in i["attributes"]:
77+
j.pop("groupId", None)
78+
j.pop("id", None)
7379
assert json1 == json2
7480
if project_type == "Pixel":
7581
assert filecmp.cmp(

0 commit comments

Comments
 (0)