Skip to content

Commit e3605db

Browse files
authored
Merge pull request #116 from roboflow/classification_annotation_upload
Classification annotation upload
2 parents c0b6bf0 + 1ab0692 commit e3605db

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

roboflow/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from roboflow.core.project import Project
99
from roboflow.core.workspace import Workspace
1010

11-
__version__ = "0.2.30"
11+
__version__ = "0.2.31"
1212

1313

1414
def check_key(api_key, model, notebook, num_retries=0):

roboflow/core/project.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,36 @@ def __image_upload(
340340

341341
return response
342342

343-
def __annotation_upload(self, annotation_path, image_id):
343+
def __annotation_upload(self, annotation_path: str, image_id: str):
344344
"""function to upload annotation to the specific project
345345
:param annotation_path: path to annotation you'd like to upload
346346
:param image_id: image id you'd like to upload that has annotations for it.
347347
"""
348-
# Get annotation string
349-
annotation_string = open(annotation_path, "r").read()
348+
349+
# stop on empty string
350+
if len(annotation_path) == 0:
351+
print("Please provide a non-empty string for annotation_path.")
352+
return {"result": "Please provide a non-empty string for annotation_path."}
353+
354+
# check if annotation file exists
355+
elif os.path.exists(annotation_path):
356+
print("-> found given annotation file")
357+
annotation_string = open(annotation_path, "r").read()
358+
359+
# if not annotation file, check if user wants to upload regular as classification annotation
360+
elif self.type == "classification":
361+
print(f"-> using {annotation_path} as classname for classification project")
362+
annotation_string = annotation_path
363+
364+
# don't attempt upload otherwise
365+
else:
366+
print(
367+
"File not found or uploading to non-classification type project with invalid string"
368+
)
369+
return {
370+
"result": "File not found or uploading to non-classification type project with invalid string"
371+
}
372+
350373
# Set annotation upload url
351374
self.annotation_upload_url = "".join(
352375
[
@@ -547,7 +570,12 @@ def single_upload(
547570
annotation_success = False
548571
# Give user warning that annotation failed to upload
549572
if not annotation_success:
550-
warnings.warn("Annotation, " + annotation_path + ", failed to upload!")
573+
warnings.warn(
574+
"Annotation, "
575+
+ annotation_path
576+
+ "failed to upload!\n Upload correct annotation file to image_id: "
577+
+ image_id
578+
)
551579
else:
552580
annotation_success = True
553581

0 commit comments

Comments
 (0)