@@ -2662,6 +2662,8 @@ def execute(self):
26622662 else :
26632663 from_s3 = None
26642664
2665+ for _ in range (len (annotations_to_upload ) - len (response .data .images )):
2666+ yield
26652667 with concurrent .futures .ThreadPoolExecutor (
26662668 max_workers = self .MAX_WORKERS
26672669 ) as executor :
@@ -2693,7 +2695,6 @@ def execute(self):
26932695 failed_annotations = [
26942696 annotation .path for annotation in failed_annotations
26952697 ]
2696-
26972698 self ._response .data = (
26982699 uploaded_annotations ,
26992700 failed_annotations ,
@@ -2705,42 +2706,41 @@ def execute(self):
27052706 def upload_to_s3 (
27062707 self , image_id : int , image_info , bucket , from_s3 , image_id_name_map
27072708 ):
2708- if from_s3 :
2709- file = io .BytesIO ()
2710- s3_object = from_s3 .Object (
2711- self ._client_s3_bucket , image_id_name_map [image_id ].path
2712- )
2713- s3_object .download_fileobj (file )
2714- file .seek (0 )
2715- annotation_json = json .load (file )
2716- else :
2717- annotation_json = json .load (open (image_id_name_map [image_id ].path ))
2718-
2719- self .fill_classes_data (annotation_json )
2720-
2721- if not self ._is_valid_json (annotation_json ):
2722- logger .warning (f"Invalid json { image_id_name_map [image_id ].path } " )
2723- return image_id_name_map [image_id ], False
2724- bucket .put_object (
2725- Key = image_info ["annotation_json_path" ], Body = json .dumps (annotation_json ),
2726- )
2727- if self ._project .project_type == constances .ProjectType .PIXEL .value :
2728- mask_filename = (
2729- image_id_name_map [image_id ].name + constances .ANNOTATION_MASK_POSTFIX
2730- )
2709+ try :
27312710 if from_s3 :
27322711 file = io .BytesIO ()
27332712 s3_object = from_s3 .Object (
2734- self ._client_s3_bucket , f" { self . _folder_path } / { mask_filename } "
2713+ self ._client_s3_bucket , image_id_name_map [ image_id ]. path
27352714 )
27362715 s3_object .download_fileobj (file )
27372716 file .seek (0 )
2717+ annotation_json = json .load (file )
27382718 else :
2739- with open (f"{ self ._folder_path } /{ mask_filename } " , "rb" ) as mask_file :
2740- file = io .BytesIO (mask_file .read ())
2741-
2742- bucket .put_object (Key = image_info ["annotation_bluemap_path" ], Body = file )
2743- return image_id_name_map [image_id ], True
2719+ annotation_json = json .load (open (image_id_name_map [image_id ].path ))
2720+ self .fill_classes_data (annotation_json )
2721+ if not self ._is_valid_json (annotation_json ):
2722+ logger .warning (f"Invalid json { image_id_name_map [image_id ].path } " )
2723+ return image_id_name_map [image_id ], False
2724+ bucket .put_object (
2725+ Key = image_info ["annotation_json_path" ], Body = json .dumps (annotation_json ),
2726+ )
2727+ if self ._project .project_type == constances .ProjectType .PIXEL .value :
2728+ mask_path = image_id_name_map [image_id ].path .replace ("___pixel.json" , constances .ANNOTATION_MASK_POSTFIX )
2729+ if from_s3 :
2730+ file = io .BytesIO ()
2731+ s3_object = from_s3 .Object (
2732+ self ._client_s3_bucket ,
2733+ mask_path
2734+ )
2735+ s3_object .download_fileobj (file )
2736+ file .seek (0 )
2737+ else :
2738+ with open (mask_path , "rb" ) as mask_file :
2739+ file = io .BytesIO (mask_file .read ())
2740+ bucket .put_object (Key = image_info ["annotation_bluemap_path" ], Body = file )
2741+ return image_id_name_map [image_id ], True
2742+ except Exception as _ :
2743+ return image_id_name_map [image_id ], False
27442744
27452745 def report_missing_data (self ):
27462746 if self .missing_classes :
0 commit comments