22import json
33import os
44import sys
5+ import time
56import warnings
67
78import requests
89from PIL import Image , UnidentifiedImageError
910
1011from roboflow .adapters import rfapi
11- from roboflow .config import API_URL , DEFAULT_BATCH_NAME , DEMO_KEYS
12+ from roboflow .config import API_URL , DEMO_KEYS
1213from roboflow .core .version import Version
1314from roboflow .util .general import retry
1415from roboflow .util .image_utils import load_labelmap
@@ -361,7 +362,7 @@ def upload(
361362 image_id : str = None ,
362363 split : str = "train" ,
363364 num_retry_uploads : int = 0 ,
364- batch_name : str = DEFAULT_BATCH_NAME ,
365+ batch_name : str = None ,
365366 tag_names : list = [],
366367 is_prediction : bool = False ,
367368 ** kwargs ,
@@ -454,7 +455,7 @@ def single_upload(
454455 image_id = None ,
455456 split = "train" ,
456457 num_retry_uploads = 0 ,
457- batch_name = DEFAULT_BATCH_NAME ,
458+ batch_name = None ,
458459 tag_names = [],
459460 is_prediction : bool = False ,
460461 annotation_overwrite = False ,
@@ -470,44 +471,64 @@ def single_upload(
470471 if isinstance (annotation_labelmap , str ):
471472 annotation_labelmap = load_labelmap (annotation_labelmap )
472473 uploaded_image , uploaded_annotation = None , None
474+ upload_time = None
473475 if image_path :
474- uploaded_image = retry (
475- num_retry_uploads ,
476- Exception ,
477- rfapi .upload_image ,
478- self .__api_key ,
479- project_url ,
480- image_path ,
481- hosted_image = hosted_image ,
482- split = split ,
483- batch_name = batch_name ,
484- tag_names = tag_names ,
485- sequence_number = sequence_number ,
486- sequence_size = sequence_size ,
487- ** kwargs ,
488- )
489- image_id = uploaded_image ["id" ]
476+ t0 = time .time ()
477+ try :
478+ uploaded_image = retry (
479+ num_retry_uploads ,
480+ Exception ,
481+ rfapi .upload_image ,
482+ self .__api_key ,
483+ project_url ,
484+ image_path ,
485+ hosted_image = hosted_image ,
486+ split = split ,
487+ batch_name = batch_name ,
488+ tag_names = tag_names ,
489+ sequence_number = sequence_number ,
490+ sequence_size = sequence_size ,
491+ ** kwargs ,
492+ )
493+ image_id = uploaded_image ["id" ]
494+ except BaseException as e :
495+ uploaded_image = {"error" : e }
496+ finally :
497+ upload_time = time .time () - t0
490498
491- if annotation_path :
499+ annotation_time = None
500+ if annotation_path and image_id :
492501 annotation_name , annotation_str = self ._annotation_params (annotation_path )
493502 try :
503+ t0 = time .time ()
494504 uploaded_annotation = rfapi .save_annotation (
495505 self .__api_key ,
496506 project_url ,
497507 annotation_name ,
498508 annotation_str ,
499509 image_id ,
510+ job_name = batch_name ,
500511 is_prediction = is_prediction ,
501512 annotation_labelmap = annotation_labelmap ,
502513 overwrite = annotation_overwrite ,
503514 )
504515 except BaseException as e :
505516 uploaded_annotation = {"error" : e }
506- return {"image" : uploaded_image , "annotation" : uploaded_annotation }
517+ finally :
518+ annotation_time = time .time () - t0
519+ return {
520+ "image" : uploaded_image ,
521+ "annotation" : uploaded_annotation ,
522+ "upload_time" : upload_time ,
523+ "annotation_time" : annotation_time ,
524+ }
507525
508526 def _annotation_params (self , annotation_path ):
509527 annotation_name , annotation_string = None , None
510- if os .path .exists (annotation_path ):
528+ if isinstance (annotation_path , dict ):
529+ annotation_name = annotation_path ["name" ]
530+ annotation_string = json .dumps (annotation_path ["parsed" ])
531+ elif os .path .exists (annotation_path ):
511532 with open (annotation_path , "r" ):
512533 annotation_string = open (annotation_path , "r" ).read ()
513534 annotation_name = os .path .basename (annotation_path )
0 commit comments