@@ -1634,13 +1634,16 @@ def execute(self):
16341634 if self .is_valid ():
16351635 if self ._image_names :
16361636 image_ids = [
1637- image ["id" ]
1638- for image in self ._backend_service .get_bulk_images (
1637+ image .uuid
1638+ for image in GetBulkImages (
1639+ service = self ._backend_service ,
16391640 project_id = self ._project .uuid ,
16401641 team_id = self ._project .team_id ,
16411642 folder_id = self ._folder .uuid ,
16421643 images = self ._image_names ,
16431644 )
1645+ .execute ()
1646+ .data
16441647 ]
16451648 else :
16461649 condition = (
@@ -3971,15 +3974,23 @@ def validate_upload_state(self):
39713974
39723975 def execute (self ):
39733976 if self .is_valid ():
3974- images = self ._service .get_duplicated_images (
3975- project_id = self ._project .uuid ,
3976- team_id = self ._project .team_id ,
3977- folder_id = self ._folder .uuid ,
3978- images = self ._images_list ,
3977+ images = (
3978+ GetBulkImages (
3979+ service = self ._service ,
3980+ project_id = self ._project .uuid ,
3981+ team_id = self ._project .team_id ,
3982+ folder_id = self ._folder .uuid ,
3983+ images = self ._images_list ,
3984+ )
3985+ .execute ()
3986+ .data
39793987 )
39803988
3981- image_ids = [image ["id" ] for image in images ]
3982- image_names = [image ["name" ] for image in images ]
3989+ image_ids = [image .uuid for image in images ]
3990+ image_names = [image .name for image in images ]
3991+
3992+ if not len (image_names ):
3993+ raise AppException ("No valid image names were provided" )
39833994
39843995 res = self ._service .run_segmentation (
39853996 self ._project .team_id ,
@@ -3990,34 +4001,39 @@ def execute(self):
39904001 if not res .ok :
39914002 return self ._response
39924003
3993- succeded_imgs = []
3994- failed_imgs = []
3995- while len (succeded_imgs ) + len (failed_imgs ) != len (image_ids ):
3996- images_metadata = self ._service .get_bulk_images (
3997- project_id = self ._project .uuid ,
3998- team_id = self ._project .team_id ,
3999- folder_id = self ._folder .uuid ,
4000- images = image_names ,
4004+ success_images = []
4005+ failed_images = []
4006+ while len (success_images ) + len (failed_images ) != len (image_ids ):
4007+ images_metadata = (
4008+ GetBulkImages (
4009+ service = self ._service ,
4010+ project_id = self ._project .uuid ,
4011+ team_id = self ._project .team_id ,
4012+ folder_id = self ._folder .uuid ,
4013+ images = self ._images_list ,
4014+ )
4015+ .execute ()
4016+ .data
40014017 )
40024018
4003- succeded_imgs = [
4004- img [ " name" ]
4019+ success_images = [
4020+ img . name
40054021 for img in images_metadata
4006- if img ["segmentation_status" ] == 3
4022+ if img .segmentation_status
4023+ == constances .SegmentationStatus .COMPLETED .value
40074024 ]
4008- failed_imgs = [
4009- img [ " name" ]
4025+ failed_images = [
4026+ img . name
40104027 for img in images_metadata
4011- if img ["segmentation_status" ] == 4
4028+ if img .segmentation_status
4029+ == constances .SegmentationStatus .FAILED .value
40124030 ]
4013-
4014- complete_images = succeded_imgs + failed_imgs
40154031 logger .info (
4016- f"segmentation complete on { len (complete_images )} / { len (image_ids )} images"
4032+ f"segmentation complete on { len (success_images + failed_images )} / { len (image_ids )} images"
40174033 )
40184034 time .sleep (5 )
40194035
4020- self ._response .data = (succeded_imgs , failed_imgs )
4036+ self ._response .data = (success_images , failed_images )
40214037 return self ._response
40224038
40234039
@@ -4040,17 +4056,23 @@ def __init__(
40404056 self ._folder = folder
40414057
40424058 def execute (self ):
4043- images = self ._service .get_duplicated_images (
4044- project_id = self ._project .uuid ,
4045- team_id = self ._project .team_id ,
4046- folder_id = self ._folder .uuid ,
4047- images = self ._images_list ,
4059+
4060+ images = (
4061+ GetBulkImages (
4062+ service = self ._service ,
4063+ project_id = self ._project .uuid ,
4064+ team_id = self ._project .team_id ,
4065+ folder_id = self ._folder .uuid ,
4066+ images = self ._images_list ,
4067+ )
4068+ .execute ()
4069+ .data
40484070 )
40494071
4050- image_ids = [image [ "id" ] for image in images ]
4051- image_names = [image [ " name" ] for image in images ]
4072+ image_ids = [image . uuid for image in images ]
4073+ image_names = [image . name for image in images ]
40524074
4053- if not image_ids :
4075+ if not len ( image_names ) :
40544076 self ._response .errors = AppException ("No valid image names were provided." )
40554077 return self ._response
40564078
@@ -4076,23 +4098,31 @@ def execute(self):
40764098 success_images = []
40774099 failed_images = []
40784100 while len (success_images ) + len (failed_images ) != len (image_ids ):
4079- images_metadata = self ._service .get_bulk_images (
4080- project_id = self ._project .uuid ,
4081- team_id = self ._project .team_id ,
4082- folder_id = self ._folder .uuid ,
4083- images = image_names ,
4101+ images_metadata = (
4102+ GetBulkImages (
4103+ service = self ._service ,
4104+ project_id = self ._project .uuid ,
4105+ team_id = self ._project .team_id ,
4106+ folder_id = self ._folder .uuid ,
4107+ images = self ._images_list ,
4108+ )
4109+ .execute ()
4110+ .data
40844111 )
40854112
40864113 success_images = [
4087- img ["name" ] for img in images_metadata if img ["prediction_status" ] == 3
4114+ img .name
4115+ for img in images_metadata
4116+ if img .segmentation_status
4117+ == constances .SegmentationStatus .COMPLETED .value
40884118 ]
40894119 failed_images = [
4090- img ["name" ] for img in images_metadata if img ["prediction_status" ] == 4
4120+ img .name
4121+ for img in images_metadata
4122+ if img .segmentation_status == constances .SegmentationStatus .FAILED .value
40914123 ]
4092-
4093- complete_images = success_images + failed_images
40944124 logger .info (
4095- f"prediction complete on { len (complete_images )} / { len (image_ids )} images"
4125+ f"Prediction complete on { len (success_images + failed_images )} / { len (image_ids )} images"
40964126 )
40974127 time .sleep (5 )
40984128
@@ -4357,20 +4387,25 @@ def images_to_upload(self):
43574387 filtered_paths = []
43584388 duplicated_paths = []
43594389
4360- get_bulk_use_case = GetDuplicateImages (
4361- service = self ._backend_client ,
4362- project_id = self ._project .uuid ,
4363- team_id = self ._project .team_id ,
4364- folder_id = self ._folder .uuid ,
4365- images = [Path (image ).name for image in paths ],
4390+ image_entities = (
4391+ GetBulkImages (
4392+ service = self ._backend_client ,
4393+ project_id = self ._project .uuid ,
4394+ team_id = self ._project .team_id ,
4395+ folder_id = self ._folder .uuid ,
4396+ images = [Path (image ).name for image in paths ],
4397+ )
4398+ .execute ()
4399+ .data
43664400 )
4367- image_names = get_bulk_use_case .execute ()
43684401
43694402 for path in paths :
43704403 not_in_exclude_list = [
43714404 x not in Path (path ).name for x in self .exclude_file_patterns
43724405 ]
4373- non_in_service_list = [x not in Path (path ).name for x in image_names ]
4406+ non_in_service_list = [
4407+ x .name not in Path (path ).name for x in image_entities
4408+ ]
43744409 if all (not_in_exclude_list ) and all (non_in_service_list ):
43754410 filtered_paths .append (path )
43764411 if not all (non_in_service_list ):
@@ -4481,7 +4516,7 @@ def execute(self) -> Response:
44814516 return self ._response
44824517
44834518
4484- class GetDuplicateImages (BaseUseCase ):
4519+ class GetBulkImages (BaseUseCase ):
44854520 def __init__ (
44864521 self ,
44874522 service : SuerannotateServiceProvider ,
@@ -4499,13 +4534,32 @@ def __init__(
44994534 self ._chunk_size = 500
45004535
45014536 def execute (self ):
4502- duplicates = []
4537+ res = []
45034538 for i in range (0 , len (self ._images ), self ._chunk_size ):
4504- duplications = self ._service .get_bulk_images (
4539+ images = self ._service .get_bulk_images (
45054540 project_id = self ._project_id ,
45064541 team_id = self ._team_id ,
45074542 folder_id = self ._folder_id ,
45084543 images = self ._images [i : i + self ._chunk_size ],
45094544 )
4510- duplicates += [image ["name" ] for image in duplications ]
4511- return duplicates
4545+ res += [
4546+ ImageEntity (
4547+ uuid = image ["id" ],
4548+ name = image ["name" ],
4549+ path = image ["name" ],
4550+ project_id = image ["project_id" ],
4551+ team_id = image ["team_id" ],
4552+ annotation_status_code = image ["annotation_status" ],
4553+ folder_id = image ["folder_id" ],
4554+ annotator_id = image ["annotator_id" ],
4555+ annotator_name = image ["annotator_name" ],
4556+ qa_id = image ["qa_id" ],
4557+ qa_name = image ["qa_name" ],
4558+ entropy_value = image ["entropy_value" ],
4559+ approval_status = image ["approval_status" ],
4560+ is_pinned = image ["is_pinned" ],
4561+ )
4562+ for image in images
4563+ ]
4564+ self ._response .data = res
4565+ return self ._response
0 commit comments