Skip to content
Merged

326 #214

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/superannotate/lib/app/interface/sdk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3412,7 +3412,9 @@ def upload_image_to_project(

if not isinstance(img, io.BytesIO):
if from_s3_bucket:
image_bytes = controller.get_image_from_s3(from_s3_bucket, image_name)
response = controller.get_image_from_s3(from_s3_bucket, img)
image_bytes = response.data

else:
image_bytes = io.BytesIO(open(img, "rb").read())
else:
Expand All @@ -3424,6 +3426,8 @@ def upload_image_to_project(
folder_name=folder_name,
image_quality_in_editor=image_quality_in_editor,
)
if upload_response.errors:
raise AppException(upload_response.errors)
controller.upload_images(
project_name=project_name,
folder_name=folder_name,
Expand Down Expand Up @@ -3517,7 +3521,10 @@ def upload_images_to_project(
with tqdm(total=len(images_to_upload), desc="Uploading images") as progress_bar:
for _ in use_case.execute():
progress_bar.update(1)
return use_case.data
uploaded, failed_images, duplications = use_case.data
if duplications:
logger.info(f"Duplicated images {', '.join(duplications)}")
return uploaded, failed_images, duplications
raise AppException(use_case.response.errors)


Expand Down
1 change: 1 addition & 0 deletions src/superannotate/lib/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Attribute(BaseModel):

class AttributeGroup(BaseModel):
name: StrictStr
is_multiselect: Optional[int]
attributes: List[Attribute]


Expand Down
13 changes: 3 additions & 10 deletions src/superannotate/lib/core/usecases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3268,9 +3268,6 @@ def execute(self):
annotations,
fuse_image,
)
logger.info(
"Downloaded image %s to %s.", self._image.name, str(download_path)
)

return self._response

Expand Down Expand Up @@ -4067,6 +4064,8 @@ def download_to_local_storage(self, destination: str):
project_id=self._project.uuid,
export_id=export["id"],
)
if "error" in export:
raise AppException(export["error"])
export_status = export["status"]
if export_status in (ExportStatus.ERROR.value, ExportStatus.CANCELED.value):
raise AppException("Couldn't download export.")
Expand Down Expand Up @@ -4877,7 +4876,7 @@ def _upload_image(self, image_path: str):
else:
try:
image_bytes = io.BytesIO(open(image_path, "rb").read())
except FileNotFoundError:
except OSError:
return ProcessedImage(
uploaded=False,
path=image_path,
Expand Down Expand Up @@ -4927,10 +4926,6 @@ def images_to_upload(self):
[extension in path for extension in self.exclude_file_patterns]
)
]
excluded_paths = [path for path in paths if path not in filtered_paths]
if excluded_paths:
logger.info(f"Excluded paths {', '.join(excluded_paths)}")

image_entities = (
GetBulkImages(
service=self._backend_client,
Expand Down Expand Up @@ -4994,8 +4989,6 @@ def execute(self):
duplications.extend(attach_duplications)
uploaded = [image["name"] for image in uploaded]
failed_images = [image.split("/")[-1] for image in failed_images]
if duplications:
logger.info(f"Duplicated images {', '.join(duplications)}")
self._response.data = uploaded, failed_images, duplications
return self._response

Expand Down
1 change: 1 addition & 0 deletions src/superannotate/lib/infrastructure/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
self._paginate_by = paginate_by
self._verify_ssl = verify_ssl
self.team_id = auth_token.split("=")[-1]
self.get_session()

@timed_lru_cache(seconds=360)
def get_session(self):
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/test_image_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import src.superannotate as sa
from tests.integration.base import BaseTestCase
from src.superannotate import AppException


class TestImageQuality(BaseTestCase):
Expand Down Expand Up @@ -59,3 +60,23 @@ def test_image_quality_setting2(self):
shallow=False,
)
)



class TestImageQuality(BaseTestCase):
PROJECT_NAME = "pixel image q"
PROJECT_DESCRIPTION = "Desc"
PROJECT_TYPE = "Pixel"
TEST_FOLDER_PATH = "data_set/big_img"
BIG_IMAGE = "big.jpg"
MESSAGE = "Image resolution 44761088 too large. Max supported for resolution is 4000000"

@property
def folder_path(self):
return os.path.join(dirname(dirname(__file__)), self.TEST_FOLDER_PATH)

def test_big_image(self):
try:
sa.upload_image_to_project(self.PROJECT_NAME,f"{self.folder_path}/{self.BIG_IMAGE}")
except AppException as e:
self.assertEqual(str(e),self.MESSAGE)
12 changes: 12 additions & 0 deletions tests/integration/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ def test_overlay_fuse(self):
)
self.assertIsNotNone(paths)

def test_upload_images_to_project_returned_data(self):
upload, not_uploaded, duplicated = sa.upload_images_to_project(
self.PROJECT_NAME,
[f"{self.folder_path}/{self.EXAMPLE_IMAGE_1}", f"{self.folder_path}/{self.EXAMPLE_IMAGE_2}"]
)
self.assertEqual(2, len(upload))
upload, not_uploaded, duplicated = sa.upload_images_to_project(
self.PROJECT_NAME,
[f"{self.folder_path}/{self.EXAMPLE_IMAGE_1}", f"{self.folder_path}/{self.EXAMPLE_IMAGE_2}"]
)
self.assertEqual(2, len(duplicated))

def test_upload_images_to_project_image_quality_in_editor(self):
self.assertRaises(
AppException,
Expand Down