@@ -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 = (
@@ -4008,7 +4011,7 @@ def __init__(
40084011 self ._folder = folder
40094012
40104013 def validate_project_type (self ):
4011- if self ._project .project_type is not ProjectType .PIXEL :
4014+ if self ._project .project_type is not ProjectType .PIXEL . value :
40124015 raise AppValidationException (
40134016 "Operation not supported for given project type"
40144017 )
@@ -4018,59 +4021,77 @@ def validate_model(self):
40184021 raise AppValidationException ("Model Does not exist" )
40194022
40204023 def validate_upload_state (self ):
4024+
40214025 if self ._project .upload_state is constances .UploadState .EXTERNAL :
40224026 raise AppValidationException (
40234027 "The function does not support projects containing images attached with URLs"
40244028 )
40254029
40264030 def execute (self ):
4027- images = self ._service .get_duplicated_images (
4028- project_id = self ._project .uuid ,
4029- team_id = self ._project .team_id ,
4030- folder_id = self ._folder .uuid ,
4031- images = self ._images_list ,
4032- )
4031+ if self .is_valid ():
4032+ images = (
4033+ GetBulkImages (
4034+ service = self ._service ,
4035+ project_id = self ._project .uuid ,
4036+ team_id = self ._project .team_id ,
4037+ folder_id = self ._folder .uuid ,
4038+ images = self ._images_list ,
4039+ )
4040+ .execute ()
4041+ .data
4042+ )
40334043
4034- image_ids = [image [ "id" ] for image in images ]
4035- image_names = [image [ " name" ] for image in images ]
4044+ image_ids = [image . uuid for image in images ]
4045+ image_names = [image . name for image in images ]
40364046
4037- res = self ._service .run_segmentation (
4038- self ._project .team_id ,
4039- self ._project .uuid ,
4040- model_name = self ._ml_model_name ,
4041- image_ids = image_ids ,
4042- )
4043- if not res .ok :
4044- return self ._response
4047+ if not len (image_names ):
4048+ self ._response .errors = AppException (
4049+ "No valid image names were provided."
4050+ )
4051+ return self ._response
40454052
4046- succeded_imgs = []
4047- failed_imgs = []
4048- while len (succeded_imgs ) + len (failed_imgs ) != len (image_ids ):
4049- images_metadata = self ._service .get_bulk_images (
4050- project_id = self ._project .uuid ,
4051- team_id = self ._project .team_id ,
4052- folder_id = self ._folder .uuid ,
4053- images = image_names ,
4053+ res = self ._service .run_segmentation (
4054+ self ._project .team_id ,
4055+ self ._project .uuid ,
4056+ model_name = self ._ml_model_name ,
4057+ image_ids = image_ids ,
40544058 )
4059+ if not res .ok :
4060+ return self ._response
40554061
4056- succeded_imgs = [
4057- img ["name" ]
4058- for img in images_metadata
4059- if img ["segmentation_status" ] == 3
4060- ]
4061- failed_imgs = [
4062- img ["name" ]
4063- for img in images_metadata
4064- if img ["segmentation_status" ] == 4
4065- ]
4062+ success_images = []
4063+ failed_images = []
4064+ while len (success_images ) + len (failed_images ) != len (image_ids ):
4065+ images_metadata = (
4066+ GetBulkImages (
4067+ service = self ._service ,
4068+ project_id = self ._project .uuid ,
4069+ team_id = self ._project .team_id ,
4070+ folder_id = self ._folder .uuid ,
4071+ images = self ._images_list ,
4072+ )
4073+ .execute ()
4074+ .data
4075+ )
40664076
4067- complete_images = succeded_imgs + failed_imgs
4068- logger .info (
4069- f"segmentation complete on { len (complete_images )} / { len (image_ids )} images"
4070- )
4071- time .sleep (5 )
4077+ success_images = [
4078+ img .name
4079+ for img in images_metadata
4080+ if img .segmentation_status
4081+ == constances .SegmentationStatus .COMPLETED .value
4082+ ]
4083+ failed_images = [
4084+ img .name
4085+ for img in images_metadata
4086+ if img .segmentation_status
4087+ == constances .SegmentationStatus .FAILED .value
4088+ ]
4089+ logger .info (
4090+ f"segmentation complete on { len (success_images + failed_images )} / { len (image_ids )} images"
4091+ )
4092+ time .sleep (5 )
40724093
4073- self ._response .data = (succeded_imgs , failed_imgs )
4094+ self ._response .data = (success_images , failed_images )
40744095 return self ._response
40754096
40764097
@@ -4093,63 +4114,82 @@ def __init__(
40934114 self ._folder = folder
40944115
40954116 def execute (self ):
4096- images = self ._service .get_duplicated_images (
4097- project_id = self ._project .uuid ,
4098- team_id = self ._project .team_id ,
4099- folder_id = self ._folder .uuid ,
4100- images = self ._images_list ,
4101- )
4102-
4103- image_ids = [image ["id" ] for image in images ]
4104- image_names = [image ["name" ] for image in images ]
4117+ if self .is_valid ():
4118+ images = (
4119+ GetBulkImages (
4120+ service = self ._service ,
4121+ project_id = self ._project .uuid ,
4122+ team_id = self ._project .team_id ,
4123+ folder_id = self ._folder .uuid ,
4124+ images = self ._images_list ,
4125+ )
4126+ .execute ()
4127+ .data
4128+ )
41054129
4106- if not image_ids :
4107- self ._response .errors = AppException ("No valid image names were provided." )
4108- return self ._response
4130+ image_ids = [image .uuid for image in images ]
4131+ image_names = [image .name for image in images ]
41094132
4110- ml_models = self ._ml_model_repo .get_all (
4111- condition = Condition ("name" , self ._ml_model_name , EQ )
4112- & Condition ("include_global" , True , EQ )
4113- & Condition ("team_id" , self ._project .team_id , EQ )
4114- )
4115- ml_model = None
4116- for model in ml_models :
4117- if model .name == self ._ml_model_name :
4118- ml_model = model
4133+ if not len (image_names ):
4134+ self ._response .errors = AppException (
4135+ "No valid image names were provided."
4136+ )
4137+ return self ._response
41194138
4120- res = self ._service .run_prediction (
4121- team_id = self ._project .team_id ,
4122- project_id = self ._project .uuid ,
4123- ml_model_id = ml_model .uuid ,
4124- image_ids = image_ids ,
4125- )
4126- if not res .ok :
4127- return self ._response
4139+ ml_models = self ._ml_model_repo .get_all (
4140+ condition = Condition ("name" , self ._ml_model_name , EQ )
4141+ & Condition ("include_global" , True , EQ )
4142+ & Condition ("team_id" , self ._project .team_id , EQ )
4143+ )
4144+ ml_model = None
4145+ for model in ml_models :
4146+ if model .name == self ._ml_model_name :
4147+ ml_model = model
41284148
4129- success_images = []
4130- failed_images = []
4131- while len (success_images ) + len (failed_images ) != len (image_ids ):
4132- images_metadata = self ._service .get_bulk_images (
4133- project_id = self ._project .uuid ,
4149+ res = self ._service .run_prediction (
41344150 team_id = self ._project .team_id ,
4135- folder_id = self ._folder .uuid ,
4136- images = image_names ,
4151+ project_id = self ._project .uuid ,
4152+ ml_model_id = ml_model .uuid ,
4153+ image_ids = image_ids ,
41374154 )
4155+ if not res .ok :
4156+ return self ._response
41384157
4139- success_images = [
4140- img ["name" ] for img in images_metadata if img ["prediction_status" ] == 3
4141- ]
4142- failed_images = [
4143- img ["name" ] for img in images_metadata if img ["prediction_status" ] == 4
4144- ]
4158+ success_images = []
4159+ failed_images = []
4160+ while len (success_images ) + len (failed_images ) != len (image_ids ):
4161+ images_metadata = (
4162+ GetBulkImages (
4163+ service = self ._service ,
4164+ project_id = self ._project .uuid ,
4165+ team_id = self ._project .team_id ,
4166+ folder_id = self ._folder .uuid ,
4167+ images = self ._images_list ,
4168+ )
4169+ .execute ()
4170+ .data
4171+ )
41454172
4146- complete_images = success_images + failed_images
4147- logger .info (
4148- f"prediction complete on { len (complete_images )} / { len (image_ids )} images"
4149- )
4150- time .sleep (5 )
4173+ success_images = [
4174+ img .name
4175+ for img in images_metadata
4176+ if img .segmentation_status
4177+ == constances .SegmentationStatus .COMPLETED .value
4178+ ]
4179+ failed_images = [
4180+ img .name
4181+ for img in images_metadata
4182+ if img .segmentation_status
4183+ == constances .SegmentationStatus .FAILED .value
4184+ ]
4185+
4186+ complete_images = success_images + failed_images
4187+ logger .info (
4188+ f"prediction complete on { len (complete_images )} / { len (image_ids )} images"
4189+ )
4190+ time .sleep (5 )
41514191
4152- self ._response .data = (success_images , failed_images )
4192+ self ._response .data = (success_images , failed_images )
41534193 return self ._response
41544194
41554195
@@ -4415,13 +4455,25 @@ def images_to_upload(self):
44154455 folder_id = self ._folder .uuid ,
44164456 images = [Path (image ).name for image in paths ],
44174457 )
4418- image_names = [image ["name" ] for image in images ]
4458+ image_entities = (
4459+ GetBulkImages (
4460+ service = self ._backend_client ,
4461+ project_id = self ._project .uuid ,
4462+ team_id = self ._project .team_id ,
4463+ folder_id = self ._folder .uuid ,
4464+ images = [Path (image ).name for image in paths ],
4465+ )
4466+ .execute ()
4467+ .data
4468+ )
44194469
44204470 for path in paths :
44214471 not_in_exclude_list = [
44224472 x not in Path (path ).name for x in self .exclude_file_patterns
44234473 ]
4424- non_in_service_list = [x not in Path (path ).name for x in image_names ]
4474+ non_in_service_list = [
4475+ x .name not in Path (path ).name for x in image_entities
4476+ ]
44254477 if (
44264478 all (not_in_exclude_list )
44274479 and all (non_in_service_list )
@@ -4546,10 +4598,19 @@ def execute(self) -> Response:
45464598 continue
45474599 else :
45484600 polling_states [poll_id ] = True
4549- logger .info ("Annotations deleted" )
45504601 continue
4602+
4603+ project_folder_name = (
4604+ self ._project .name
4605+ + (f"/{ self ._folder .name } " if self ._folder .name != "root" else "" )
4606+ + "."
4607+ )
4608+
45514609 if all (polling_states .values ()):
4552- logger .info ("Annotations deleted" )
4610+ logger .info (
4611+ "The annotations have been successfully deleted from "
4612+ + project_folder_name
4613+ )
45534614 else :
45544615 logger .info ("Annotations delete fails." )
45554616 return self ._response
@@ -4581,6 +4642,24 @@ def execute(self):
45814642 folder_id = self ._folder_id ,
45824643 images = self ._images [i : i + self ._chunk_size ],
45834644 )
4584- res += [ImageEntity .from_dict (** image ) for image in images ]
4645+ res += [
4646+ ImageEntity (
4647+ uuid = image ["id" ],
4648+ name = image ["name" ],
4649+ path = image ["name" ],
4650+ project_id = image ["project_id" ],
4651+ team_id = image ["team_id" ],
4652+ annotation_status_code = image ["annotation_status" ],
4653+ folder_id = image ["folder_id" ],
4654+ annotator_id = image ["annotator_id" ],
4655+ annotator_name = image ["annotator_name" ],
4656+ qa_id = image ["qa_id" ],
4657+ qa_name = image ["qa_name" ],
4658+ entropy_value = image ["entropy_value" ],
4659+ approval_status = image ["approval_status" ],
4660+ is_pinned = image ["is_pinned" ],
4661+ )
4662+ for image in images
4663+ ]
45854664 self ._response .data = res
45864665 return self ._response
0 commit comments