Skip to content

Commit 9fc201d

Browse files
committed
Fix CLI preannotation thread
1 parent c1bd84c commit 9fc201d

File tree

2 files changed

+67
-52
lines changed

2 files changed

+67
-52
lines changed

superannotate/db/projects.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,11 @@ def _upload_annotations_from_folder_to_project(
12831283
finish_event.set()
12841284
tqdm_thread.join()
12851285
logger.info("Number of annotations uploaded %s.", sum(num_uploaded))
1286+
if sum(num_uploaded) != len_annotations_paths:
1287+
logger.warning(
1288+
"%s annotations were not uploaded.",
1289+
len_annotations_paths - sum(num_uploaded)
1290+
)
12861291

12871292
for ac_upl in actually_uploaded:
12881293
return_result += [str(p) for p in ac_upl]
@@ -1512,36 +1517,38 @@ def _upload_preannotations_from_folder_to_project(
15121517
annotation_classes_dict = get_annotation_classes_name_to_id(
15131518
annotation_classes
15141519
)
1515-
while True:
1516-
if sum(num_uploaded) == len_preannotations_paths:
1517-
break
1518-
response = _api.send_request(
1519-
req_type='GET',
1520-
path=f'/project/{project_id}/preannotation',
1521-
params=params
1520+
response = _api.send_request(
1521+
req_type='GET',
1522+
path=f'/project/{project_id}/preannotation',
1523+
params=params
1524+
)
1525+
if not response.ok:
1526+
raise SABaseException(response.status_code, response.text)
1527+
aws_creds = response.json()
1528+
1529+
threads = []
1530+
for thread_id in range(_NUM_THREADS):
1531+
t = threading.Thread(
1532+
target=__upload_preannotations_thread,
1533+
args=(
1534+
aws_creds, project_type, preannotations_filenames, folder_path,
1535+
annotation_classes_dict, thread_id, chunksize, num_uploaded,
1536+
already_uploaded, from_s3_bucket
1537+
),
1538+
daemon=True
15221539
)
1523-
if not response.ok:
1524-
raise SABaseException(response.status_code, response.text)
1525-
aws_creds = response.json()
1526-
1527-
threads = []
1528-
for thread_id in range(_NUM_THREADS):
1529-
t = threading.Thread(
1530-
target=__upload_preannotations_thread,
1531-
args=(
1532-
aws_creds, project_type, preannotations_filenames,
1533-
folder_path, annotation_classes_dict, thread_id, chunksize,
1534-
num_uploaded, already_uploaded, from_s3_bucket
1535-
),
1536-
daemon=True
1537-
)
1538-
threads.append(t)
1539-
t.start()
1540-
for t in threads:
1541-
t.join()
1540+
threads.append(t)
1541+
t.start()
1542+
for t in threads:
1543+
t.join()
15421544
finish_event.set()
15431545
tqdm_thread.join()
15441546
logger.info("Number of preannotations uploaded %s.", sum(num_uploaded))
1547+
if sum(num_uploaded) != len_preannotations_paths:
1548+
logger.warning(
1549+
"%s preannotations were not uploaded.",
1550+
len_preannotations_paths - sum(num_uploaded)
1551+
)
15451552
return return_result + [str(p) for p in preannotations_paths]
15461553

15471554

tests/test_preannotation_upload_cli.py

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,24 +66,21 @@ def test_annotation_folder_upload_download_cli_vector_COCO(tmpdir):
6666
sa.upload_images_from_folder_to_project(
6767
project, from_folder, annotation_status="InProgress"
6868
)
69-
# sa.create_annotation_classes_from_classes_json(
70-
# project, from_folder / "classes" / "classes.json"
71-
# )
7269
subprocess.run(
7370
f'superannotatecli upload-annotations --project "{name}" --folder "{from_folder}" --format COCO --task {task} --dataset-name {dataset_name}',
7471
check=True,
7572
shell=True
7673
)
77-
# time.sleep(5)
78-
# count_in = len(list(from_folder.glob("*.json")))
74+
time.sleep(5)
75+
count_in = 2
7976

80-
# images = sa.search_images(project)
81-
# for image_name in images:
82-
# sa.download_image_preannotations(project, image_name, tmpdir)
77+
images = sa.search_images(project)
78+
for image_name in images:
79+
sa.download_image_annotations(project, image_name, tmpdir)
8380

84-
# count_out = len(list(Path(tmpdir).glob("*.json")))
81+
count_out = len(list(Path(tmpdir).glob("*.json")))
8582

86-
# assert count_in == count_out
83+
assert count_in == count_out
8784

8885

8986
def test_preannotation_folder_upload_download_cli_vector_COCO(tmpdir):
@@ -102,24 +99,21 @@ def test_preannotation_folder_upload_download_cli_vector_COCO(tmpdir):
10299
sa.upload_images_from_folder_to_project(
103100
project, from_folder, annotation_status="InProgress"
104101
)
105-
# sa.create_annotation_classes_from_classes_json(
106-
# project, from_folder / "classes" / "classes.json"
107-
# )
108102
subprocess.run(
109103
f'superannotatecli upload-preannotations --project "{name}" --folder "{from_folder}" --format COCO --task {task} --dataset-name {dataset_name}',
110104
check=True,
111105
shell=True
112106
)
113-
# time.sleep(5)
114-
# count_in = len(list(from_folder.glob("*.json")))
107+
time.sleep(5)
108+
count_in = 2
115109

116-
# images = sa.search_images(project)
117-
# for image_name in images:
118-
# sa.download_image_preannotations(project, image_name, tmpdir)
110+
images = sa.search_images(project)
111+
for image_name in images:
112+
sa.download_image_preannotations(project, image_name, tmpdir)
119113

120-
# count_out = len(list(Path(tmpdir).glob("*.json")))
114+
count_out = len(list(Path(tmpdir).glob("*.json")))
121115

122-
# assert count_in == count_out
116+
assert count_in == count_out
123117

124118

125119
def test_preannotation_folder_upload_download_cli_vector_object_COCO(tmpdir):
@@ -138,14 +132,21 @@ def test_preannotation_folder_upload_download_cli_vector_object_COCO(tmpdir):
138132
sa.upload_images_from_folder_to_project(
139133
project, from_folder, annotation_status="InProgress"
140134
)
141-
# sa.create_annotation_classes_from_classes_json(
142-
# project, from_folder / "classes" / "classes.json"
143-
# )
144135
subprocess.run(
145136
f'superannotatecli upload-preannotations --project "{name}" --folder "{from_folder}" --format COCO --task {task} --dataset-name {dataset_name}',
146137
check=True,
147138
shell=True
148139
)
140+
time.sleep(5)
141+
count_in = 4
142+
143+
images = sa.search_images(project)
144+
for image_name in images:
145+
sa.download_image_preannotations(project, image_name, tmpdir)
146+
147+
count_out = len(list(Path(tmpdir).glob("*.json")))
148+
149+
assert count_in == count_out
149150

150151

151152
def test_preannotation_folder_upload_download_cli_pixel_object_COCO(tmpdir):
@@ -164,11 +165,18 @@ def test_preannotation_folder_upload_download_cli_pixel_object_COCO(tmpdir):
164165
sa.upload_images_from_folder_to_project(
165166
project, from_folder, annotation_status="InProgress"
166167
)
167-
# sa.create_annotation_classes_from_classes_json(
168-
# project, from_folder / "classes" / "classes.json"
169-
# )
170168
subprocess.run(
171169
f'superannotatecli upload-preannotations --project "{name}" --folder "{from_folder}" --format COCO --task {task} --dataset-name {dataset_name}',
172170
check=True,
173171
shell=True
174172
)
173+
time.sleep(5)
174+
count_in = 6
175+
176+
images = sa.search_images(project)
177+
for image_name in images:
178+
sa.download_image_preannotations(project, image_name, tmpdir)
179+
180+
count_out = len(list(Path(tmpdir).glob("*.json")))
181+
182+
assert count_in == count_out

0 commit comments

Comments
 (0)