@@ -1684,13 +1684,16 @@ def execute(self):
16841684 if self .is_valid ():
16851685 if self ._image_names :
16861686 image_ids = [
1687- image ["id" ]
1688- for image in self ._backend_service .get_bulk_images (
1687+ image .uuid
1688+ for image in GetBulkImages (
1689+ service = self ._backend_service ,
16891690 project_id = self ._project .uuid ,
16901691 team_id = self ._project .team_id ,
16911692 folder_id = self ._folder .uuid ,
16921693 images = self ._image_names ,
16931694 )
1695+ .execute ()
1696+ .data
16941697 ]
16951698 else :
16961699 condition = (
@@ -4010,7 +4013,7 @@ def __init__(
40104013 self ._folder = folder
40114014
40124015 def validate_project_type (self ):
4013- if self ._project .project_type is not ProjectType .PIXEL :
4016+ if self ._project .project_type is not ProjectType .PIXEL . value :
40144017 raise AppValidationException (
40154018 "Operation not supported for given project type"
40164019 )
@@ -4020,59 +4023,77 @@ def validate_model(self):
40204023 raise AppValidationException ("Model Does not exist" )
40214024
40224025 def validate_upload_state (self ):
4026+
40234027 if self ._project .upload_state is constances .UploadState .EXTERNAL :
40244028 raise AppValidationException (
40254029 "The function does not support projects containing images attached with URLs"
40264030 )
40274031
40284032 def execute (self ):
4029- images = self ._service .get_duplicated_images (
4030- project_id = self ._project .uuid ,
4031- team_id = self ._project .team_id ,
4032- folder_id = self ._folder .uuid ,
4033- images = self ._images_list ,
4034- )
4033+ if self .is_valid ():
4034+ images = (
4035+ GetBulkImages (
4036+ service = self ._service ,
4037+ project_id = self ._project .uuid ,
4038+ team_id = self ._project .team_id ,
4039+ folder_id = self ._folder .uuid ,
4040+ images = self ._images_list ,
4041+ )
4042+ .execute ()
4043+ .data
4044+ )
40354045
4036- image_ids = [image [ "id" ] for image in images ]
4037- image_names = [image [ " name" ] for image in images ]
4046+ image_ids = [image . uuid for image in images ]
4047+ image_names = [image . name for image in images ]
40384048
4039- res = self ._service .run_segmentation (
4040- self ._project .team_id ,
4041- self ._project .uuid ,
4042- model_name = self ._ml_model_name ,
4043- image_ids = image_ids ,
4044- )
4045- if not res .ok :
4046- return self ._response
4049+ if not len (image_names ):
4050+ self ._response .errors = AppException (
4051+ "No valid image names were provided."
4052+ )
4053+ return self ._response
40474054
4048- succeded_imgs = []
4049- failed_imgs = []
4050- while len (succeded_imgs ) + len (failed_imgs ) != len (image_ids ):
4051- images_metadata = self ._service .get_bulk_images (
4052- project_id = self ._project .uuid ,
4053- team_id = self ._project .team_id ,
4054- folder_id = self ._folder .uuid ,
4055- images = image_names ,
4055+ res = self ._service .run_segmentation (
4056+ self ._project .team_id ,
4057+ self ._project .uuid ,
4058+ model_name = self ._ml_model_name ,
4059+ image_ids = image_ids ,
40564060 )
4061+ if not res .ok :
4062+ return self ._response
40574063
4058- succeded_imgs = [
4059- img ["name" ]
4060- for img in images_metadata
4061- if img ["segmentation_status" ] == 3
4062- ]
4063- failed_imgs = [
4064- img ["name" ]
4065- for img in images_metadata
4066- if img ["segmentation_status" ] == 4
4067- ]
4064+ success_images = []
4065+ failed_images = []
4066+ while len (success_images ) + len (failed_images ) != len (image_ids ):
4067+ images_metadata = (
4068+ GetBulkImages (
4069+ service = self ._service ,
4070+ project_id = self ._project .uuid ,
4071+ team_id = self ._project .team_id ,
4072+ folder_id = self ._folder .uuid ,
4073+ images = self ._images_list ,
4074+ )
4075+ .execute ()
4076+ .data
4077+ )
40684078
4069- complete_images = succeded_imgs + failed_imgs
4070- logger .info (
4071- f"segmentation complete on { len (complete_images )} / { len (image_ids )} images"
4072- )
4073- time .sleep (5 )
4079+ success_images = [
4080+ img .name
4081+ for img in images_metadata
4082+ if img .segmentation_status
4083+ == constances .SegmentationStatus .COMPLETED .value
4084+ ]
4085+ failed_images = [
4086+ img .name
4087+ for img in images_metadata
4088+ if img .segmentation_status
4089+ == constances .SegmentationStatus .FAILED .value
4090+ ]
4091+ logger .info (
4092+ f"segmentation complete on { len (success_images + failed_images )} / { len (image_ids )} images"
4093+ )
4094+ time .sleep (5 )
40744095
4075- self ._response .data = (succeded_imgs , failed_imgs )
4096+ self ._response .data = (success_images , failed_images )
40764097 return self ._response
40774098
40784099
@@ -4095,63 +4116,82 @@ def __init__(
40954116 self ._folder = folder
40964117
40974118 def execute (self ):
4098- images = self ._service .get_duplicated_images (
4099- project_id = self ._project .uuid ,
4100- team_id = self ._project .team_id ,
4101- folder_id = self ._folder .uuid ,
4102- images = self ._images_list ,
4103- )
4104-
4105- image_ids = [image ["id" ] for image in images ]
4106- image_names = [image ["name" ] for image in images ]
4119+ if self .is_valid ():
4120+ images = (
4121+ GetBulkImages (
4122+ service = self ._service ,
4123+ project_id = self ._project .uuid ,
4124+ team_id = self ._project .team_id ,
4125+ folder_id = self ._folder .uuid ,
4126+ images = self ._images_list ,
4127+ )
4128+ .execute ()
4129+ .data
4130+ )
41074131
4108- if not image_ids :
4109- self ._response .errors = AppException ("No valid image names were provided." )
4110- return self ._response
4132+ image_ids = [image .uuid for image in images ]
4133+ image_names = [image .name for image in images ]
41114134
4112- ml_models = self ._ml_model_repo .get_all (
4113- condition = Condition ("name" , self ._ml_model_name , EQ )
4114- & Condition ("include_global" , True , EQ )
4115- & Condition ("team_id" , self ._project .team_id , EQ )
4116- )
4117- ml_model = None
4118- for model in ml_models :
4119- if model .name == self ._ml_model_name :
4120- ml_model = model
4135+ if not len (image_names ):
4136+ self ._response .errors = AppException (
4137+ "No valid image names were provided."
4138+ )
4139+ return self ._response
41214140
4122- res = self ._service .run_prediction (
4123- team_id = self ._project .team_id ,
4124- project_id = self ._project .uuid ,
4125- ml_model_id = ml_model .uuid ,
4126- image_ids = image_ids ,
4127- )
4128- if not res .ok :
4129- return self ._response
4141+ ml_models = self ._ml_model_repo .get_all (
4142+ condition = Condition ("name" , self ._ml_model_name , EQ )
4143+ & Condition ("include_global" , True , EQ )
4144+ & Condition ("team_id" , self ._project .team_id , EQ )
4145+ )
4146+ ml_model = None
4147+ for model in ml_models :
4148+ if model .name == self ._ml_model_name :
4149+ ml_model = model
41304150
4131- success_images = []
4132- failed_images = []
4133- while len (success_images ) + len (failed_images ) != len (image_ids ):
4134- images_metadata = self ._service .get_bulk_images (
4135- project_id = self ._project .uuid ,
4151+ res = self ._service .run_prediction (
41364152 team_id = self ._project .team_id ,
4137- folder_id = self ._folder .uuid ,
4138- images = image_names ,
4153+ project_id = self ._project .uuid ,
4154+ ml_model_id = ml_model .uuid ,
4155+ image_ids = image_ids ,
41394156 )
4157+ if not res .ok :
4158+ return self ._response
41404159
4141- success_images = [
4142- img ["name" ] for img in images_metadata if img ["prediction_status" ] == 3
4143- ]
4144- failed_images = [
4145- img ["name" ] for img in images_metadata if img ["prediction_status" ] == 4
4146- ]
4160+ success_images = []
4161+ failed_images = []
4162+ while len (success_images ) + len (failed_images ) != len (image_ids ):
4163+ images_metadata = (
4164+ GetBulkImages (
4165+ service = self ._service ,
4166+ project_id = self ._project .uuid ,
4167+ team_id = self ._project .team_id ,
4168+ folder_id = self ._folder .uuid ,
4169+ images = self ._images_list ,
4170+ )
4171+ .execute ()
4172+ .data
4173+ )
41474174
4148- complete_images = success_images + failed_images
4149- logger .info (
4150- f"prediction complete on { len (complete_images )} / { len (image_ids )} images"
4151- )
4152- time .sleep (5 )
4175+ success_images = [
4176+ img .name
4177+ for img in images_metadata
4178+ if img .segmentation_status
4179+ == constances .SegmentationStatus .COMPLETED .value
4180+ ]
4181+ failed_images = [
4182+ img .name
4183+ for img in images_metadata
4184+ if img .segmentation_status
4185+ == constances .SegmentationStatus .FAILED .value
4186+ ]
4187+
4188+ complete_images = success_images + failed_images
4189+ logger .info (
4190+ f"prediction complete on { len (complete_images )} / { len (image_ids )} images"
4191+ )
4192+ time .sleep (5 )
41534193
4154- self ._response .data = (success_images , failed_images )
4194+ self ._response .data = (success_images , failed_images )
41554195 return self ._response
41564196
41574197
@@ -4417,13 +4457,25 @@ def images_to_upload(self):
44174457 folder_id = self ._folder .uuid ,
44184458 images = [Path (image ).name for image in paths ],
44194459 )
4420- image_names = [image ["name" ] for image in images ]
4460+ image_entities = (
4461+ GetBulkImages (
4462+ service = self ._backend_client ,
4463+ project_id = self ._project .uuid ,
4464+ team_id = self ._project .team_id ,
4465+ folder_id = self ._folder .uuid ,
4466+ images = [Path (image ).name for image in paths ],
4467+ )
4468+ .execute ()
4469+ .data
4470+ )
44214471
44224472 for path in paths :
44234473 not_in_exclude_list = [
44244474 x not in Path (path ).name for x in self .exclude_file_patterns
44254475 ]
4426- non_in_service_list = [x not in Path (path ).name for x in image_names ]
4476+ non_in_service_list = [
4477+ x .name not in Path (path ).name for x in image_entities
4478+ ]
44274479 if (
44284480 all (not_in_exclude_list )
44294481 and all (non_in_service_list )
@@ -4548,10 +4600,19 @@ def execute(self) -> Response:
45484600 continue
45494601 else :
45504602 polling_states [poll_id ] = True
4551- logger .info ("Annotations deleted" )
45524603 continue
4604+
4605+ project_folder_name = (
4606+ self ._project .name
4607+ + (f"/{ self ._folder .name } " if self ._folder .name != "root" else "" )
4608+ + "."
4609+ )
4610+
45534611 if all (polling_states .values ()):
4554- logger .info ("Annotations deleted" )
4612+ logger .info (
4613+ "The annotations have been successfully deleted from "
4614+ + project_folder_name
4615+ )
45554616 else :
45564617 logger .info ("Annotations delete fails." )
45574618 return self ._response
0 commit comments