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
17 changes: 10 additions & 7 deletions src/superannotate/lib/core/usecases/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def _upload_annotation(
bucket,
):
try:
self.reporter.disable_warnings()
response = UploadAnnotationUseCase(
project=self._project,
folder=self._folder,
Expand Down Expand Up @@ -196,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 @@ -231,8 +234,7 @@ def _log_report(self):
logger.warning(
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"Use the validate_annotations function to discover the possible reason(s) for "
f"which an annotation is invalid."
f"{constances.USE_VALIDATE_MESSAGE}"
)

def execute(self):
Expand Down Expand Up @@ -486,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
7 changes: 7 additions & 0 deletions src/superannotate/lib/core/usecases/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,13 @@ def _copy_workflow(

def execute(self):
if self.is_valid():
if self._project_to_create.project_type in (
constances.ProjectType.PIXEL.value,
constances.ProjectType.VECTOR.value,
):
self._project_to_create.upload_state = (
constances.UploadState.INITIAL.value
)
project = self._projects.insert(self._project_to_create)
self.reporter.log_info(
f"Created project {self._project_to_create.name} with type"
Expand Down
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
3 changes: 2 additions & 1 deletion tests/integration/projects/test_clone_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
import src.superannotate as sa
from tests import DATA_SET_PATH
from src.superannotate import constances


class TestCloneProject(TestCase):
Expand Down Expand Up @@ -78,7 +79,7 @@ def test_create_like_project(self):
self.PROJECT_NAME_2, self.PROJECT_NAME_1, copy_contributors=True
)
source_project = sa.get_project_metadata(self.PROJECT_NAME_1)
self.assertEqual(new_project['upload_state'], source_project['upload_state'])
self.assertEqual(new_project['upload_state'], constances.UploadState.INITIAL.name)

new_settings = sa.get_project_settings(self.PROJECT_NAME_2)
image_quality = None
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