@@ -1020,7 +1020,7 @@ def execute(self):
10201020 headers = annotations ["annotation_json_path" ]["headers" ],
10211021 )
10221022 if not response .ok :
1023- raise AppException (f"Couldn't load annotations { response . text } " )
1023+ raise AppException (f"Couldn't load annotations. " )
10241024
10251025 image_annotations = response .json ()
10261026 from_project_annotation_classes = (
@@ -1111,7 +1111,7 @@ def execute(self):
11111111 headers = annotations ["annotation_bluemap_path" ]["headers" ],
11121112 )
11131113 if not response .ok :
1114- raise AppException (f"Couldn't load annotations { response . text } " )
1114+ raise AppException (f"Couldn't load annotations. " )
11151115 self .to_project_s3_repo .insert (
11161116 S3FileEntity (
11171117 auth_data ["annotation_bluemap_path" ]["filePath" ], response .content
@@ -2036,7 +2036,7 @@ def execute(self):
20362036 headers = credentials ["annotation_json_path" ]["headers" ],
20372037 )
20382038 if not response .ok :
2039- logger .warning (f"Couldn't load annotations { response . text } " )
2039+ logger .warning (f"Couldn't load annotations. " )
20402040 self ._response .data = data
20412041 return self ._response
20422042 data ["annotation_json" ] = response .json ()
@@ -2131,7 +2131,7 @@ def execute(self):
21312131 url = annotation_json_creds ["url" ], headers = annotation_json_creds ["headers" ],
21322132 )
21332133 if not response .ok :
2134- raise AppException (f"Couldn't load annotations { response . text } " )
2134+ raise AppException (f"Couldn't load annotations. " )
21352135 data ["preannotation_json" ] = response .json ()
21362136 data ["preannotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
21372137 if self ._project .project_type == constances .ProjectType .PIXEL .value :
@@ -2208,7 +2208,7 @@ def execute(self):
22082208 headers = annotation_json_creds ["headers" ],
22092209 )
22102210 if not response .ok :
2211- logger .warning (f"Couldn't load annotations { response . text } " )
2211+ logger .warning (f"Couldn't load annotations. " )
22122212 self ._response .data = (None , None )
22132213 return self ._response
22142214 data ["annotation_json" ] = response .json ()
@@ -2287,7 +2287,7 @@ def execute(self):
22872287 url = annotation_json_creds ["url" ], headers = annotation_json_creds ["headers" ],
22882288 )
22892289 if not response .ok :
2290- raise AppException (f"Couldn't load annotations { response . text } " )
2290+ raise AppException (f"Couldn't load annotations. " )
22912291 data ["preannotation_json" ] = response .json ()
22922292 data ["preannotation_json_filename" ] = f"{ self ._image_name } { file_postfix } "
22932293 mask_path = None
@@ -3147,6 +3147,7 @@ def execute(self):
31473147
31483148
31493149class UploadAnnotationsUseCase (BaseUseCase ):
3150+ MAX_WORKERS = 10
31503151 def __init__ (
31513152 self ,
31523153 project : ProjectEntity ,
@@ -3326,42 +3327,9 @@ def execute(self):
33263327 else :
33273328 from_s3 = None
33283329
3329- for image_id , image_info in auth_data ["images" ].items ():
3330- if from_s3 :
3331- file = io .BytesIO ()
3332- s3_object = from_s3 .Object (
3333- self ._client_s3_bucket , image_id_name_map [image_id ].path
3334- )
3335- s3_object .download_fileobj (file )
3336- file .seek (0 )
3337- annotation_json = json .load (file )
3338- else :
3339- annotation_json = json .load (open (image_id_name_map [image_id ].path ))
3340-
3341- self .fill_classes_data (annotation_json )
3342- bucket .put_object (
3343- Key = image_info ["annotation_json_path" ],
3344- Body = json .dumps (annotation_json ),
3345- )
3346- if self ._project .project_type == constances .ProjectType .PIXEL .value :
3347- mask_filename = (
3348- image_id_name_map [image_id ].name
3349- + constances .ANNOTATION_MASK_POSTFIX
3350- )
3351- if from_s3 :
3352- file = io .BytesIO ()
3353- s3_object = self ._client_s3_bucket .Objcect (
3354- self ._client_s3_bucket , self ._folder_path + mask_filename
3355- )
3356- s3_object .download_file (file )
3357- file .seek (0 )
3358- else :
3359- with open (
3360- f"{ self ._folder_path } /{ mask_filename } " , "rb"
3361- ) as mask_file :
3362- file = io .BytesIO (mask_file .read ())
3363-
3364- bucket .put_object (Key = image_info ["annotation_bluemap_path" ], Body = file )
3330+ with concurrent .futures .ThreadPoolExecutor (max_workers = self .MAX_WORKERS ) as executor :
3331+ for image_id , image_info in auth_data ["images" ].items ():
3332+ executor .submit (self .upload_to_s3 , image_id , image_info , bucket , from_s3 , image_id_name_map )
33653333
33663334 uploaded_annotations = [annotation .path for annotation in annotations_to_upload ]
33673335 missing_annotations = [annotation .path for annotation in missing_annotations ]
@@ -3377,6 +3345,43 @@ def execute(self):
33773345 )
33783346 return self ._response
33793347
3348+ def upload_to_s3 (self , image_id : int , image_info , bucket , from_s3 , image_id_name_map ):
3349+ if from_s3 :
3350+ file = io .BytesIO ()
3351+ s3_object = from_s3 .Object (
3352+ self ._client_s3_bucket , image_id_name_map [image_id ].path
3353+ )
3354+ s3_object .download_fileobj (file )
3355+ file .seek (0 )
3356+ annotation_json = json .load (file )
3357+ else :
3358+ annotation_json = json .load (open (image_id_name_map [image_id ].path ))
3359+
3360+ self .fill_classes_data (annotation_json )
3361+ bucket .put_object (
3362+ Key = image_info ["annotation_json_path" ],
3363+ Body = json .dumps (annotation_json ),
3364+ )
3365+ if self ._project .project_type == constances .ProjectType .PIXEL .value :
3366+ mask_filename = (
3367+ image_id_name_map [image_id ].name
3368+ + constances .ANNOTATION_MASK_POSTFIX
3369+ )
3370+ if from_s3 :
3371+ file = io .BytesIO ()
3372+ s3_object = self ._client_s3_bucket .Objcect (
3373+ self ._client_s3_bucket , self ._folder_path + mask_filename
3374+ )
3375+ s3_object .download_file (file )
3376+ file .seek (0 )
3377+ else :
3378+ with open (
3379+ f"{ self ._folder_path } /{ mask_filename } " , "rb"
3380+ ) as mask_file :
3381+ file = io .BytesIO (mask_file .read ())
3382+
3383+ bucket .put_object (Key = image_info ["annotation_bluemap_path" ], Body = file )
3384+
33803385
33813386class CreateModelUseCase (BaseUseCase ):
33823387 def __init__ (
0 commit comments