Skip to content

Commit 4d77db5

Browse files
authored
Merge pull request #195 from superannotateai/s3_recursive
Fix s3_recursive annotations
2 parents 1f4a389 + 4897403 commit 4d77db5

File tree

2 files changed

+56
-33
lines changed

2 files changed

+56
-33
lines changed

src/superannotate/lib/core/usecases.py

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,9 +2231,10 @@ def execute(self):
22312231
url=annotation_blue_map_creds["url"],
22322232
headers=annotation_blue_map_creds["headers"],
22332233
)
2234+
data["annotation_mask_filename"] = f"{self._image_name}___save.png"
2235+
22342236
if response.ok:
22352237
data["annotation_mask"] = io.BytesIO(response.content)
2236-
data["annotation_mask_filename"] = f"{self._image_name}___save.png"
22372238
mask_path = (
22382239
Path(self._destination) / data["annotation_mask_filename"]
22392240
)
@@ -4480,58 +4481,63 @@ def paths(self):
44804481
):
44814482
paths.append(key)
44824483
break
4483-
4484-
data = []
4485-
for path in paths:
4486-
if all(
4487-
[
4488-
True if exclude_pattern not in str(path) else False
4489-
for exclude_pattern in self.exclude_file_patterns
4490-
]
4491-
):
4492-
data.append(str(path))
4493-
return data
4484+
return [str(path) for path in paths]
44944485

44954486
@property
44964487
def images_to_upload(self):
44974488
if not self._images_to_upload:
44984489
paths = self.paths
44994490
filtered_paths = []
45004491
duplicated_paths = []
4492+
for path in paths:
4493+
if path.split("/")[-1] not in [
4494+
path_name.split("/")[-1] for path_name in filtered_paths
4495+
]:
4496+
filtered_paths.append(path)
4497+
else:
4498+
duplicated_paths.append(path)
4499+
filtered_paths = [
4500+
path
4501+
for path in filtered_paths
4502+
if not any(
4503+
[
4504+
path.endswith(extension)
4505+
for extension in self.exclude_file_patterns
4506+
]
4507+
)
4508+
]
4509+
duplicated_paths = [
4510+
path
4511+
for path in duplicated_paths
4512+
if not any(
4513+
[
4514+
path.endswith(extension)
4515+
for extension in self.exclude_file_patterns
4516+
]
4517+
)
4518+
]
4519+
45014520
image_entities = (
45024521
GetBulkImages(
45034522
service=self._backend_client,
45044523
project_id=self._project.uuid,
45054524
team_id=self._project.team_id,
45064525
folder_id=self._folder.uuid,
4507-
images=[Path(image).name for image in paths],
4526+
images=[image.split("/")[-1] for image in filtered_paths],
45084527
)
45094528
.execute()
45104529
.data
45114530
)
4531+
images_to_upload = []
4532+
image_list = [image.name for image in image_entities]
45124533

4513-
for path in paths:
4514-
not_in_exclude_list = [
4515-
x not in Path(path).name for x in self.exclude_file_patterns
4516-
]
4517-
non_in_service_list = [
4518-
x.name not in Path(path).name for x in image_entities
4519-
]
4520-
if (
4521-
all(not_in_exclude_list)
4522-
and all(non_in_service_list)
4523-
and not any(
4524-
Path(path).name in filtered_path
4525-
for filtered_path in filtered_paths
4526-
)
4527-
):
4528-
filtered_paths.append(path)
4529-
elif not all(non_in_service_list) or any(
4530-
Path(path).name in filtered_path for filtered_path in filtered_paths
4531-
):
4534+
for path in filtered_paths:
4535+
if path not in image_list:
4536+
images_to_upload.append(path)
4537+
else:
45324538
duplicated_paths.append(path)
45334539

4534-
self._images_to_upload = list(set(filtered_paths)), duplicated_paths
4540+
self._images_to_upload = list(set(images_to_upload)), duplicated_paths
45354541
return self._images_to_upload
45364542

45374543
def execute(self):

tests/integration/test_recursive_folder.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,23 @@ def test_images_non_recursive_s3(self):
269269

270270
self.assertEqual(len(sa.search_images(self.PROJECT_NAME)), 1)
271271

272+
273+
274+
275+
def test_images_recursive_s3_122(self):
276+
sa.upload_images_from_folder_to_project(self.PROJECT_NAME, '8sep', from_s3_bucket="superannotate-python-sdk-test",recursive_subfolders=True)
277+
self.assertEqual(len(sa.search_images(self.PROJECT_NAME)), 122)
278+
279+
280+
def test_annotations_recursive_s3_122(self):
281+
sa.upload_images_from_folder_to_project(self.PROJECT_NAME, '8sep', from_s3_bucket="superannotate-python-sdk-test",recursive_subfolders=True)
282+
sa.upload_annotations_from_folder_to_project(self.PROJECT_NAME, '8sep', from_s3_bucket="superannotate-python-sdk-test",recursive_subfolders=True)
283+
annotations = sa.get_image_annotations(self.PROJECT_NAME,"e13cb60a2bf31c22d2524518b7444f92e37fe5d404b0144390f8c078a0eabd_640.jpg")[
284+
"annotation_json"
285+
]
286+
self.assertEqual(len(annotations['instances']),1)
287+
288+
272289
def test_images_non_recursive(self):
273290
sa.upload_images_from_folder_to_project(
274291
self.PROJECT_NAME, self.folder_path, recursive_subfolders=False

0 commit comments

Comments
 (0)