Skip to content

Commit

Permalink
Merge pull request #116 from roboflow/classification_annotation_upload
Browse files Browse the repository at this point in the history
Classification annotation upload
  • Loading branch information
ogjaylowe authored Feb 18, 2023
2 parents c0b6bf0 + 1ab0692 commit e3605db
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion roboflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from roboflow.core.project import Project
from roboflow.core.workspace import Workspace

__version__ = "0.2.30"
__version__ = "0.2.31"


def check_key(api_key, model, notebook, num_retries=0):
Expand Down
36 changes: 32 additions & 4 deletions roboflow/core/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,13 +340,36 @@ 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()

# 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
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":
print(f"-> using {annotation_path} as classname for classification project")
annotation_string = annotation_path

# don't attempt upload otherwise
else:
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(
[
Expand Down Expand Up @@ -547,7 +570,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

Expand Down

0 comments on commit e3605db

Please sign in to comment.