@@ -467,6 +467,71 @@ def upload(
467
467
print ("[ " + path + " ] was skipped." )
468
468
continue
469
469
470
+ def upload_image (
471
+ self ,
472
+ image_path = None ,
473
+ hosted_image = False ,
474
+ split = "train" ,
475
+ num_retry_uploads = 0 ,
476
+ batch_name = None ,
477
+ tag_names = [],
478
+ sequence_number = None ,
479
+ sequence_size = None ,
480
+ ** kwargs ,
481
+ ):
482
+ project_url = self .id .rsplit ("/" )[1 ]
483
+
484
+ t0 = time .time ()
485
+ retry = Retry (num_retry_uploads , ImageUploadError )
486
+
487
+ image = retry (
488
+ rfapi .upload_image ,
489
+ self .__api_key ,
490
+ project_url ,
491
+ image_path ,
492
+ hosted_image = hosted_image ,
493
+ split = split ,
494
+ batch_name = batch_name ,
495
+ tag_names = tag_names ,
496
+ sequence_number = sequence_number ,
497
+ sequence_size = sequence_size ,
498
+ ** kwargs ,
499
+ )
500
+
501
+ upload_retry_attempts = retry .retries
502
+ upload_time = time .time () - t0
503
+
504
+ return image , upload_time , upload_retry_attempts
505
+
506
+ def save_annotation (
507
+ self ,
508
+ annotation_path = None ,
509
+ annotation_labelmap = None ,
510
+ image_id = None ,
511
+ batch_name = None ,
512
+ is_prediction : bool = False ,
513
+ annotation_overwrite = False ,
514
+ ):
515
+ project_url = self .id .rsplit ("/" )[1 ]
516
+ annotation_name , annotation_str = self ._annotation_params (annotation_path )
517
+ t0 = time .time ()
518
+
519
+ annotation = rfapi .save_annotation (
520
+ self .__api_key ,
521
+ project_url ,
522
+ annotation_name , # type: ignore[type-var]
523
+ annotation_str , # type: ignore[type-var]
524
+ image_id ,
525
+ job_name = batch_name , # type: ignore[type-var]
526
+ is_prediction = is_prediction ,
527
+ annotation_labelmap = annotation_labelmap ,
528
+ overwrite = annotation_overwrite ,
529
+ )
530
+
531
+ upload_time = time .time () - t0
532
+
533
+ return annotation , upload_time
534
+
470
535
def single_upload (
471
536
self ,
472
537
image_path = None ,
@@ -484,56 +549,42 @@ def single_upload(
484
549
sequence_size = None ,
485
550
** kwargs ,
486
551
):
487
- project_url = self . id . rsplit ( "/" )[ 1 ]
552
+
488
553
if image_path and image_id :
489
554
raise Exception ("You can't pass both image_id and image_path" )
490
555
if not (image_path or image_id ):
491
556
raise Exception ("You need to pass image_path or image_id" )
492
557
if isinstance (annotation_labelmap , str ):
493
558
annotation_labelmap = load_labelmap (annotation_labelmap )
559
+
494
560
uploaded_image , uploaded_annotation = None , None
495
- upload_time = None
561
+ upload_time , annotation_time = None , None
496
562
upload_retry_attempts = 0
563
+
497
564
if image_path :
498
- t0 = time .time ()
499
- try :
500
- retry = Retry (num_retry_uploads , ImageUploadError )
501
- uploaded_image = retry (
502
- rfapi .upload_image ,
503
- self .__api_key ,
504
- project_url ,
505
- image_path ,
506
- hosted_image = hosted_image ,
507
- split = split ,
508
- batch_name = batch_name ,
509
- tag_names = tag_names ,
510
- sequence_number = sequence_number ,
511
- sequence_size = sequence_size ,
512
- ** kwargs ,
513
- )
514
- image_id = uploaded_image ["id" ] # type: ignore[index]
515
- upload_retry_attempts = retry .retries
516
- finally :
517
- upload_time = time .time () - t0
565
+ uploaded_image , upload_time , upload_retry_attempts = self .upload_image (
566
+ image_path ,
567
+ hosted_image ,
568
+ split ,
569
+ num_retry_uploads ,
570
+ batch_name ,
571
+ tag_names ,
572
+ sequence_number ,
573
+ sequence_size ,
574
+ ** kwargs ,
575
+ )
576
+ image_id = uploaded_image ["id" ] # type: ignore[index]
518
577
519
- annotation_time = None
520
578
if annotation_path and image_id :
521
- annotation_name , annotation_str = self ._annotation_params (annotation_path )
522
- try :
523
- t0 = time .time ()
524
- uploaded_annotation = rfapi .save_annotation (
525
- self .__api_key ,
526
- project_url ,
527
- annotation_name , # type: ignore[type-var]
528
- annotation_str , # type: ignore[type-var]
529
- image_id ,
530
- job_name = batch_name , # type: ignore[type-var]
531
- is_prediction = is_prediction ,
532
- annotation_labelmap = annotation_labelmap ,
533
- overwrite = annotation_overwrite ,
534
- )
535
- finally :
536
- annotation_time = time .time () - t0
579
+ uploaded_annotation , annotation_time = self .save_annotation (
580
+ annotation_path ,
581
+ annotation_labelmap ,
582
+ image_id ,
583
+ batch_name ,
584
+ is_prediction ,
585
+ annotation_overwrite ,
586
+ )
587
+
537
588
return {
538
589
"image" : uploaded_image ,
539
590
"annotation" : uploaded_annotation ,
0 commit comments