Skip to content

Commit 8e9f707

Browse files
committed
Fix s3_recursive annotations
1 parent 97bba85 commit 8e9f707

File tree

2 files changed

+59
-35
lines changed

2 files changed

+59
-35
lines changed

src/superannotate/lib/core/usecases.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ def execute(self):
320320
if self.is_valid():
321321
for field, value in self._project_data.items():
322322
setattr(self._project, field, value)
323-
self._projects.update(self._project)
323+
self._response.data = self._projects.update(self._project)
324+
return self._response
324325

325326

326327
class CloneProjectUseCase(BaseUseCase):
@@ -2229,16 +2230,17 @@ def execute(self):
22292230
url=annotation_blue_map_creds["url"],
22302231
headers=annotation_blue_map_creds["headers"],
22312232
)
2233+
data["annotation_mask_filename"] = f"{self._image_name}___save.png"
2234+
22322235
if response.ok:
22332236
data["annotation_mask"] = io.BytesIO(response.content)
2234-
data["annotation_mask_filename"] = f"{self._image_name}___save.png"
22352237
mask_path = (
22362238
Path(self._destination) / data["annotation_mask_filename"]
22372239
)
22382240
with open(mask_path, "wb") as f:
22392241
f.write(data["annotation_mask"].getbuffer())
22402242
else:
2241-
logger.info(f"There is no blue-map for the image.")
2243+
logger.info("There is no blue-map for the image.")
22422244

22432245
json_path = Path(self._destination) / data["annotation_json_filename"]
22442246
with open(json_path, "w") as f:
@@ -4478,58 +4480,63 @@ def paths(self):
44784480
):
44794481
paths.append(key)
44804482
break
4481-
4482-
data = []
4483-
for path in paths:
4484-
if all(
4485-
[
4486-
True if exclude_pattern not in str(path) else False
4487-
for exclude_pattern in self.exclude_file_patterns
4488-
]
4489-
):
4490-
data.append(str(path))
4491-
return data
4483+
return [str(path) for path in paths]
44924484

44934485
@property
44944486
def images_to_upload(self):
44954487
if not self._images_to_upload:
44964488
paths = self.paths
44974489
filtered_paths = []
44984490
duplicated_paths = []
4491+
for path in paths:
4492+
if path.split("/")[-1] not in [
4493+
path_name.split("/")[-1] for path_name in filtered_paths
4494+
]:
4495+
filtered_paths.append(path)
4496+
else:
4497+
duplicated_paths.append(path)
4498+
filtered_paths = [
4499+
path
4500+
for path in filtered_paths
4501+
if not any(
4502+
[
4503+
path.endswith(extension)
4504+
for extension in self.exclude_file_patterns
4505+
]
4506+
)
4507+
]
4508+
duplicated_paths = [
4509+
path
4510+
for path in duplicated_paths
4511+
if not any(
4512+
[
4513+
path.endswith(extension)
4514+
for extension in self.exclude_file_patterns
4515+
]
4516+
)
4517+
]
4518+
44994519
image_entities = (
45004520
GetBulkImages(
45014521
service=self._backend_client,
45024522
project_id=self._project.uuid,
45034523
team_id=self._project.team_id,
45044524
folder_id=self._folder.uuid,
4505-
images=[Path(image).name for image in paths],
4525+
images=[image.split("/")[-1] for image in filtered_paths],
45064526
)
45074527
.execute()
45084528
.data
45094529
)
4530+
images_to_upload = []
4531+
image_list = [image.name for image in image_entities]
45104532

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

4532-
self._images_to_upload = list(set(filtered_paths)), duplicated_paths
4539+
self._images_to_upload = list(set(images_to_upload)), duplicated_paths
45334540
return self._images_to_upload
45344541

45354542
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)