From 482e2d08891b1d4659a922c587bb3d9136d62361 Mon Sep 17 00:00:00 2001 From: ogjaylowe Date: Fri, 17 Feb 2023 13:08:51 -0800 Subject: [PATCH 1/3] classification annotation upload logic --- roboflow/core/project.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/roboflow/core/project.py b/roboflow/core/project.py index 2a5e6c08..5821e451 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -339,13 +339,27 @@ def __image_upload( return response - def __annotation_upload(self, annotation_path, image_id): + def __annotation_upload(self, annotation_path: str, image_id: str): """function to upload annotation to the specific project :param annotation_path: path to annotation you'd like to upload :param image_id: image id you'd like to upload that has annotations for it. """ - # Get annotation string - annotation_string = open(annotation_path, "r").read() + + # check if annotation file exists + if os.path.exists(annotation_path): + print("-> found given annotation file") + annotation_string = open(annotation_path, "r").read() + + # if not annotation file, check if user wants to upload regular as classification annotation + elif self.type == "classification" and type(annotation_path) == str: + print(f"-> using {annotation_path} as classname for classification project") + annotation_string = annotation_path + + # don't attempt upload otherwise + else: + print("file not found and project type not classification") + return {"result": "file not found and project type not classification"} + # Set annotation upload url self.annotation_upload_url = "".join( [ From a1bfe7d8de893ded5c519af28060f9404d2519d7 Mon Sep 17 00:00:00 2001 From: ogjaylowe Date: Fri, 17 Feb 2023 13:31:49 -0800 Subject: [PATCH 2/3] handling for empty string --- roboflow/core/project.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/roboflow/core/project.py b/roboflow/core/project.py index 5821e451..9a12ef79 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -345,20 +345,29 @@ def __annotation_upload(self, annotation_path: str, image_id: str): :param image_id: image id you'd like to upload that has annotations for it. """ + # stop on empty string + if len(annotation_path) == 0: + print("Please provide a non-empty string for annotation_path.") + return {"result": "Please provide a non-empty string for annotation_path."} + # check if annotation file exists - if os.path.exists(annotation_path): + elif os.path.exists(annotation_path): print("-> found given annotation file") annotation_string = open(annotation_path, "r").read() # if not annotation file, check if user wants to upload regular as classification annotation - elif self.type == "classification" and type(annotation_path) == str: + elif self.type == "classification": print(f"-> using {annotation_path} as classname for classification project") annotation_string = annotation_path # don't attempt upload otherwise else: - print("file not found and project type not classification") - return {"result": "file not found and project type not classification"} + print( + "File not found or uploading to non-classification type project with invalid string" + ) + return { + "result": "File not found or uploading to non-classification type project with invalid string" + } # Set annotation upload url self.annotation_upload_url = "".join( @@ -555,7 +564,12 @@ def single_upload( annotation_success = False # Give user warning that annotation failed to upload if not annotation_success: - warnings.warn("Annotation, " + annotation_path + ", failed to upload!") + warnings.warn( + "Annotation, " + + annotation_path + + "failed to upload!\n Upload correct annotation file to image_id: " + + image_id + ) else: annotation_success = True From d9789cd56bb3bee9e77b32af0384082bdf879c83 Mon Sep 17 00:00:00 2001 From: ogjaylowe Date: Fri, 17 Feb 2023 21:21:15 -0800 Subject: [PATCH 3/3] version uptick --- roboflow/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roboflow/__init__.py b/roboflow/__init__.py index dac8119a..51cff735 100644 --- a/roboflow/__init__.py +++ b/roboflow/__init__.py @@ -8,7 +8,7 @@ from roboflow.core.project import Project from roboflow.core.workspace import Workspace -__version__ = "0.2.29" +__version__ = "0.2.31" def check_key(api_key, model, notebook, num_retries=0):