Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/superannotate/lib/app/interface/sdk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -2112,7 +2112,7 @@ def upload_image_annotations(
mask=mask,
verbose=verbose,
)
if response.errors:
if response.errors and not response.errors == constances.INVALID_JSON_MESSAGE:
raise AppException(response.errors)


Expand Down
8 changes: 8 additions & 0 deletions src/superannotate/lib/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@
" Run 'pip install --upgrade superannotate' to"
" upgrade from your version {} to {}"
)

USE_VALIDATE_MESSAGE = (
"Use the validate_annotations function to discover the possible reason(s) for "
"which an annotation is invalid."
)

INVALID_JSON_MESSAGE = "Invalid json"

__alL__ = (
ProjectType,
UserRole,
Expand Down
6 changes: 6 additions & 0 deletions src/superannotate/lib/core/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def __init__(
self.custom_messages = defaultdict(set)
self.progress_bar = None

def disable_warnings(self):
self._log_warning = False

def enable_warnings(self):
self._log_warning = True

def log_info(self, value: str):
if self._log_info:
self.logger.info(value)
Expand Down
26 changes: 19 additions & 7 deletions src/superannotate/lib/core/usecases/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def annotations_to_upload(self):
self._annotations_to_upload = annotations_to_upload
return self._annotations_to_upload

@property
def missing_annotations(self):
if not self._missing_annotations:
self._missing_annotations = []
return self._missing_annotations

def get_annotation_upload_data(
self, image_ids: List[int]
) -> UploadAnnotationAuthData:
Expand All @@ -162,6 +168,7 @@ def _upload_annotation(
bucket,
):
try:
self.reporter.disable_warnings()
response = UploadAnnotationUseCase(
project=self._project,
folder=self._folder,
Expand Down Expand Up @@ -190,6 +197,8 @@ def _upload_annotation(
except Exception as e:
logger.debug(str(e), exc_info=True)
return path, False
finally:
self.reporter.enable_warnings()

def get_bucket_to_upload(self, ids: List[int]):
upload_data = self.get_annotation_upload_data(ids)
Expand Down Expand Up @@ -223,7 +232,9 @@ def _log_report(self):
logger.warning(template.format("', '".join(values)))
if self.reporter.custom_messages.get("invalid_jsons"):
logger.warning(
f"Couldn't validate {len(self.reporter.custom_messages['invalid_jsons'])}/{len(self._annotations_to_upload + self._missing_annotations)} annotations from {self._folder_path}."
f"Couldn't validate {len(self.reporter.custom_messages['invalid_jsons'])}/"
f"{len(self.annotations_to_upload + self.missing_annotations)} annotations from {self._folder_path}. "
f"{constances.USE_VALIDATE_MESSAGE}"
)

def execute(self):
Expand Down Expand Up @@ -281,7 +292,7 @@ def execute(self):
self._response.data = (
uploaded_annotations,
failed_annotations,
[annotation.path for annotation in self._missing_annotations],
[annotation.path for annotation in self.missing_annotations],
)
return self._response

Expand Down Expand Up @@ -477,12 +488,13 @@ def execute(self):
)
self._images.update(self._image)
if self._verbose:
logger.info(
"Uploading annotations for image %s in project %s.",
str(self._image.name),
self._project.name,
self.reporter.log_info(
f"Uploading annotations for image {str(self._image.name)} in project {self._project.name}."
)
else:
self._response.errors = "Invalid json"
self._response.errors = constances.INVALID_JSON_MESSAGE
self.reporter.store_message("invalid_jsons", self._annotation_path)
self.reporter.log_warning(
f"Couldn't validate annotations. {constances.USE_VALIDATE_MESSAGE}"
)
return self._response
4 changes: 1 addition & 3 deletions src/superannotate/lib/infrastructure/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def team_id(self) -> int:

@property
def default_reporter(self):
if not self._reporter:
self._reporter = Reporter()
return self._reporter
return Reporter()

@timed_lru_cache(seconds=3600)
def get_auth_data(self, project_id: int, team_id: int, folder_id: int):
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ def test_download_fuse_without_classes(self):
)
self.assertIsNotNone(result)

def test_validate_log_for_single_uplaod(self):
with self.assertLogs() as logs:
sa.upload_image_to_project(self.PROJECT_NAME, f"{self.folder_path}/{self.EXAMPLE_IMAGE_1}")
sa.upload_image_annotations(
self.PROJECT_NAME, self.EXAMPLE_IMAGE_1, {
"metadatas": {
"name": "example_image_1.jpg",
"width": 1024,
"height": 683,
"status": "Completed",
},
"instance": []
}
)
self.assertEqual(len(logs[1][0]), 150)



class TestPixelInterface(BaseTestCase):
PROJECT_NAME = "Interface Pixel test"
Expand Down