Skip to content

Commit c68a04a

Browse files
committed
Fix pixel recursive
1 parent 266d702 commit c68a04a

File tree

3 files changed

+70
-35
lines changed

3 files changed

+70
-35
lines changed

src/superannotate/lib/app/interface/sdk_interface.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,11 +2392,14 @@ def upload_annotations_from_folder_to_project(
23922392
annotation_paths=annotation_paths, # noqa: E203
23932393
client_s3_bucket=from_s3_bucket,
23942394
)
2395-
with tqdm(
2396-
total=len(annotation_paths), desc="Uploading annotations"
2397-
) as progress_bar:
2398-
for _ in use_case.execute():
2399-
progress_bar.update(1)
2395+
if use_case.is_valid():
2396+
with tqdm(
2397+
total=len(use_case.annotations_to_upload), desc="Uploading annotations"
2398+
) as progress_bar:
2399+
for _ in use_case.execute():
2400+
progress_bar.update(1)
2401+
else:
2402+
raise AppException(use_case.response.errors)
24002403
return use_case.data
24012404

24022405

src/superannotate/lib/core/usecases/images.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,8 @@ def execute(self):
26622662
else:
26632663
from_s3 = None
26642664

2665+
for _ in range(len(annotations_to_upload) - len(response.data.images)):
2666+
yield
26652667
with concurrent.futures.ThreadPoolExecutor(
26662668
max_workers=self.MAX_WORKERS
26672669
) as executor:
@@ -2693,7 +2695,6 @@ def execute(self):
26932695
failed_annotations = [
26942696
annotation.path for annotation in failed_annotations
26952697
]
2696-
26972698
self._response.data = (
26982699
uploaded_annotations,
26992700
failed_annotations,
@@ -2705,42 +2706,41 @@ def execute(self):
27052706
def upload_to_s3(
27062707
self, image_id: int, image_info, bucket, from_s3, image_id_name_map
27072708
):
2708-
if from_s3:
2709-
file = io.BytesIO()
2710-
s3_object = from_s3.Object(
2711-
self._client_s3_bucket, image_id_name_map[image_id].path
2712-
)
2713-
s3_object.download_fileobj(file)
2714-
file.seek(0)
2715-
annotation_json = json.load(file)
2716-
else:
2717-
annotation_json = json.load(open(image_id_name_map[image_id].path))
2718-
2719-
self.fill_classes_data(annotation_json)
2720-
2721-
if not self._is_valid_json(annotation_json):
2722-
logger.warning(f"Invalid json {image_id_name_map[image_id].path}")
2723-
return image_id_name_map[image_id], False
2724-
bucket.put_object(
2725-
Key=image_info["annotation_json_path"], Body=json.dumps(annotation_json),
2726-
)
2727-
if self._project.project_type == constances.ProjectType.PIXEL.value:
2728-
mask_filename = (
2729-
image_id_name_map[image_id].name + constances.ANNOTATION_MASK_POSTFIX
2730-
)
2709+
try:
27312710
if from_s3:
27322711
file = io.BytesIO()
27332712
s3_object = from_s3.Object(
2734-
self._client_s3_bucket, f"{self._folder_path}/{mask_filename}"
2713+
self._client_s3_bucket, image_id_name_map[image_id].path
27352714
)
27362715
s3_object.download_fileobj(file)
27372716
file.seek(0)
2717+
annotation_json = json.load(file)
27382718
else:
2739-
with open(f"{self._folder_path}/{mask_filename}", "rb") as mask_file:
2740-
file = io.BytesIO(mask_file.read())
2741-
2742-
bucket.put_object(Key=image_info["annotation_bluemap_path"], Body=file)
2743-
return image_id_name_map[image_id], True
2719+
annotation_json = json.load(open(image_id_name_map[image_id].path))
2720+
self.fill_classes_data(annotation_json)
2721+
if not self._is_valid_json(annotation_json):
2722+
logger.warning(f"Invalid json {image_id_name_map[image_id].path}")
2723+
return image_id_name_map[image_id], False
2724+
bucket.put_object(
2725+
Key=image_info["annotation_json_path"], Body=json.dumps(annotation_json),
2726+
)
2727+
if self._project.project_type == constances.ProjectType.PIXEL.value:
2728+
mask_path = image_id_name_map[image_id].path.replace("___pixel.json", constances.ANNOTATION_MASK_POSTFIX)
2729+
if from_s3:
2730+
file = io.BytesIO()
2731+
s3_object = from_s3.Object(
2732+
self._client_s3_bucket,
2733+
mask_path
2734+
)
2735+
s3_object.download_fileobj(file)
2736+
file.seek(0)
2737+
else:
2738+
with open(mask_path, "rb") as mask_file:
2739+
file = io.BytesIO(mask_file.read())
2740+
bucket.put_object(Key=image_info["annotation_bluemap_path"], Body=file)
2741+
return image_id_name_map[image_id], True
2742+
except Exception as _:
2743+
return image_id_name_map[image_id], False
27442744

27452745
def report_missing_data(self):
27462746
if self.missing_classes:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
from os.path import dirname
3+
4+
import src.superannotate as sa
5+
from tests.integration.base import BaseTestCase
6+
7+
8+
class TestRecursiveFolderPixel(BaseTestCase):
9+
PROJECT_NAME = "pixel_recursive_test"
10+
PROJECT_DESCRIPTION = "Desc"
11+
PROJECT_TYPE = "Pixel"
12+
S3_FOLDER_PATH = "pixel_all_fuse"
13+
JSON_POSTFIX = "*.json"
14+
15+
16+
def test_recursive_upload_pixel(self):
17+
uploaded, _, duplicated = sa.upload_images_from_folder_to_project(self.PROJECT_NAME,
18+
self.S3_FOLDER_PATH,
19+
from_s3_bucket="test-openseadragon-1212",
20+
recursive_subfolders=True
21+
)
22+
23+
uploaded, failed, missing = sa.upload_annotations_from_folder_to_project(self.PROJECT_NAME,
24+
self.S3_FOLDER_PATH,
25+
from_s3_bucket="test-openseadragon-1212",
26+
recursive_subfolders=True
27+
)
28+
self.assertEqual(115, len(uploaded))
29+
self.assertEqual(0, len(failed))
30+
self.assertEqual(0, len(missing))
31+
32+

0 commit comments

Comments
 (0)