@@ -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