1111import requests
1212
1313from roboflow .adapters import rfapi
14- from roboflow .adapters .rfapi import ImageUploadError
14+ from roboflow .adapters .rfapi import AnnotationSaveError , ImageUploadError
1515from roboflow .config import API_URL , DEMO_KEYS
1616from roboflow .core .version import Version
1717from roboflow .util .general import Retry
@@ -515,26 +515,34 @@ def save_annotation(
515515 job_name = None ,
516516 is_prediction : bool = False ,
517517 annotation_overwrite = False ,
518+ num_retry_uploads = 0 ,
518519 ):
519520 project_url = self .id .rsplit ("/" )[1 ]
520521 annotation_name , annotation_str = self ._annotation_params (annotation_path )
521522 t0 = time .time ()
523+ upload_retry_attempts = 0
524+ retry = Retry (num_retry_uploads , AnnotationSaveError )
522525
523- annotation = rfapi .save_annotation (
524- self .__api_key ,
525- project_url ,
526- annotation_name , # type: ignore[type-var]
527- annotation_str , # type: ignore[type-var]
528- image_id ,
529- job_name = job_name , # type: ignore[type-var]
530- is_prediction = is_prediction ,
531- annotation_labelmap = annotation_labelmap ,
532- overwrite = annotation_overwrite ,
533- )
526+ try :
527+ annotation = rfapi .save_annotation (
528+ self .__api_key ,
529+ project_url ,
530+ annotation_name , # type: ignore[type-var]
531+ annotation_str , # type: ignore[type-var]
532+ image_id ,
533+ job_name = job_name , # type: ignore[type-var]
534+ is_prediction = is_prediction ,
535+ annotation_labelmap = annotation_labelmap ,
536+ overwrite = annotation_overwrite ,
537+ )
538+ upload_retry_attempts = retry .retries
539+ except AnnotationSaveError as e :
540+ e .retries = upload_retry_attempts
541+ raise
534542
535543 upload_time = time .time () - t0
536544
537- return annotation , upload_time
545+ return annotation , upload_time , upload_retry_attempts
538546
539547 def single_upload (
540548 self ,
@@ -563,6 +571,7 @@ def single_upload(
563571 uploaded_image , uploaded_annotation = None , None
564572 upload_time , annotation_time = None , None
565573 upload_retry_attempts = 0
574+ annotation_upload_retry_attempts = 0
566575
567576 if image_path :
568577 uploaded_image , upload_time , upload_retry_attempts = self .upload_image (
@@ -579,13 +588,14 @@ def single_upload(
579588 image_id = uploaded_image ["id" ] # type: ignore[index]
580589
581590 if annotation_path and image_id :
582- uploaded_annotation , annotation_time = self .save_annotation (
591+ uploaded_annotation , annotation_time , annotation_upload_retry_attempts = self .save_annotation (
583592 annotation_path ,
584593 annotation_labelmap ,
585594 image_id ,
586595 batch_name ,
587596 is_prediction ,
588597 annotation_overwrite ,
598+ num_retry_uploads = num_retry_uploads ,
589599 )
590600
591601 return {
@@ -594,6 +604,7 @@ def single_upload(
594604 "upload_time" : upload_time ,
595605 "annotation_time" : annotation_time ,
596606 "upload_retry_attempts" : upload_retry_attempts ,
607+ "annotation_upload_retry_attempts" : annotation_upload_retry_attempts ,
597608 }
598609
599610 def _annotation_params (self , annotation_path ):
0 commit comments