|
17 | 17 | from typing import Optional |
18 | 18 |
|
19 | 19 | import boto3 |
20 | | -import botocore.exceptions |
21 | 20 | import cv2 |
22 | 21 | import lib.core as constances |
23 | 22 | import numpy as np |
24 | 23 | import pandas as pd |
25 | 24 | import requests |
| 25 | +from botocore.exceptions import ClientError |
26 | 26 | from lib.app.analytics.common import aggregate_annotations_as_df |
27 | 27 | from lib.app.analytics.common import consensus_plot |
28 | 28 | from lib.app.analytics.common import image_consensus |
@@ -805,7 +805,7 @@ def __init__( |
805 | 805 | ): |
806 | 806 | super().__init__(), |
807 | 807 | self._project = project |
808 | | - self._folder_names = folder_names |
| 808 | + self._folder_names = list(folder_names) |
809 | 809 | self._backend_service = backend_service_provider |
810 | 810 | self._annotation_statuses = annotation_statuses |
811 | 811 | self._include_fuse = include_fuse |
@@ -855,12 +855,12 @@ def execute(self): |
855 | 855 | if "error" in response: |
856 | 856 | raise AppException(response["error"]) |
857 | 857 |
|
858 | | - report_message = self._project.name |
| 858 | + report_message = "" |
859 | 859 | if self._folder_names: |
860 | | - report_message = f"[{', '.join(self._folder_names)}]" |
| 860 | + report_message = f"[{', '.join(self._folder_names)}] " |
861 | 861 | logger.info( |
862 | | - f"Prepared export {response['name']} for project " |
863 | | - f"{report_message} (project ID {self._project.uuid})." |
| 862 | + f"Prepared export {response['name']} for project {self._project.name} " |
| 863 | + f"{report_message}(project ID {self._project.uuid})." |
864 | 864 | ) |
865 | 865 | self._response.data = response |
866 | 866 |
|
@@ -2156,14 +2156,19 @@ def __init__( |
2156 | 2156 | self._image_path = image_path |
2157 | 2157 |
|
2158 | 2158 | def execute(self): |
2159 | | - image = io.BytesIO() |
2160 | | - session = boto3.Session() |
2161 | | - resource = session.resource("s3") |
2162 | | - image_object = resource.Object(self._s3_bucket, self._image_path) |
2163 | | - if image_object.content_length > constances.MAX_IMAGE_SIZE: |
2164 | | - raise AppValidationException(f"File size is {image_object.content_length}") |
2165 | | - image_object.download_fileobj(image) |
2166 | | - self._response.data = image |
| 2159 | + try: |
| 2160 | + image = io.BytesIO() |
| 2161 | + session = boto3.Session() |
| 2162 | + resource = session.resource("s3") |
| 2163 | + image_object = resource.Object(self._s3_bucket, self._image_path) |
| 2164 | + if image_object.content_length > constances.MAX_IMAGE_SIZE: |
| 2165 | + raise AppValidationException( |
| 2166 | + f"File size is {image_object.content_length}" |
| 2167 | + ) |
| 2168 | + image_object.download_fileobj(image) |
| 2169 | + self._response.data = image |
| 2170 | + except ClientError as e: |
| 2171 | + self._response.errors = str(e) |
2167 | 2172 | return self._response |
2168 | 2173 |
|
2169 | 2174 |
|
@@ -3431,19 +3436,21 @@ def execute(self): |
3431 | 3436 | ) |
3432 | 3437 | if self._project.project_type == constances.ProjectType.PIXEL.value: |
3433 | 3438 | mask_path = None |
3434 | | - if os.path.exists(self._annotation_path) and not self._mask: |
3435 | | - mask_path = self._annotation_path |
| 3439 | + png_path = self._annotation_path.replace( |
| 3440 | + "___pixel.json", "___save.png" |
| 3441 | + ) |
| 3442 | + if os.path.exists(png_path) and not self._mask: |
| 3443 | + mask_path = png_path |
3436 | 3444 | elif self._mask: |
3437 | 3445 | mask_path = self._mask |
3438 | 3446 |
|
3439 | 3447 | if mask_path: |
3440 | 3448 | with open(mask_path, "rb") as descriptor: |
3441 | | - file = io.BytesIO(descriptor.read()) |
3442 | 3449 | bucket.put_object( |
3443 | 3450 | Key=response.data.images[image_data["id"]][ |
3444 | 3451 | "annotation_bluemap_path" |
3445 | 3452 | ], |
3446 | | - Body=file, |
| 3453 | + Body=descriptor.read(), |
3447 | 3454 | ) |
3448 | 3455 | if self._verbose: |
3449 | 3456 | logger.info( |
@@ -4162,7 +4169,7 @@ def execute(self): |
4162 | 4169 | mapper_path, |
4163 | 4170 | os.path.join(self._download_path, "classes_mapper.json"), |
4164 | 4171 | ) |
4165 | | - except botocore.exceptions.ClientError: |
| 4172 | + except ClientError: |
4166 | 4173 | logger.info( |
4167 | 4174 | "The specified model does not contain a classes_mapper and/or a metrics file." |
4168 | 4175 | ) |
@@ -4853,11 +4860,20 @@ def _upload_image(self, image_path: str): |
4853 | 4860 | "ProcessedImage", ["uploaded", "path", "entity", "name"] |
4854 | 4861 | ) |
4855 | 4862 | if self._from_s3_bucket: |
4856 | | - image_bytes = ( |
4857 | | - GetS3ImageUseCase(s3_bucket=self._from_s3_bucket, image_path=image_path) |
4858 | | - .execute() |
4859 | | - .data |
4860 | | - ) |
| 4863 | + response = GetS3ImageUseCase( |
| 4864 | + s3_bucket=self._from_s3_bucket, image_path=image_path |
| 4865 | + ).execute() |
| 4866 | + if response.errors: |
| 4867 | + logger.warning( |
| 4868 | + f"Unable to upload image {image_path} \n{response.errors}" |
| 4869 | + ) |
| 4870 | + return ProcessedImage( |
| 4871 | + uploaded=False, |
| 4872 | + path=image_path, |
| 4873 | + entity=None, |
| 4874 | + name=Path(image_path).name, |
| 4875 | + ) |
| 4876 | + image_bytes = response.data |
4861 | 4877 | else: |
4862 | 4878 | try: |
4863 | 4879 | image_bytes = io.BytesIO(open(image_path, "rb").read()) |
@@ -4934,7 +4950,6 @@ def images_to_upload(self): |
4934 | 4950 | images_to_upload.append(path) |
4935 | 4951 | else: |
4936 | 4952 | duplicated_paths.append(path) |
4937 | | - |
4938 | 4953 | self._images_to_upload = list(set(images_to_upload)), duplicated_paths |
4939 | 4954 | return self._images_to_upload |
4940 | 4955 |
|
@@ -4979,7 +4994,8 @@ def execute(self): |
4979 | 4994 | duplications.extend(attach_duplications) |
4980 | 4995 | uploaded = [image["name"] for image in uploaded] |
4981 | 4996 | failed_images = [image.split("/")[-1] for image in failed_images] |
4982 | | - |
| 4997 | + if duplications: |
| 4998 | + logger.info(f"Duplicated images {', '.join(duplications)}") |
4983 | 4999 | self._response.data = uploaded, failed_images, duplications |
4984 | 5000 | return self._response |
4985 | 5001 |
|
|
0 commit comments