@@ -835,14 +835,17 @@ def execute(self):
835835
836836 outline_color = 4 * (255 ,)
837837 for instance in self .annotations ["instances" ]:
838- if (not instance .get ("className" )) or (not class_color_map .get (instance ["className" ])):
838+ if (not instance .get ("className" )) or (
839+ not class_color_map .get (instance ["className" ])
840+ ):
839841 continue
840842 color = class_color_map .get (instance ["className" ])
841843 if not color :
842844 class_color_map [instance ["className" ]] = self .generate_color ()
843845 for image in images :
844846 fill_color = (
845- * class_color_map [instance ["className" ]], 255 if image .type == "fuse" else self .TRANSPARENCY
847+ * class_color_map [instance ["className" ]],
848+ 255 if image .type == "fuse" else self .TRANSPARENCY ,
846849 )
847850 if instance ["type" ] == "bbox" :
848851 image .content .draw_bbox (
@@ -911,7 +914,9 @@ def execute(self):
911914 weight , height = image .get_size ()
912915 empty_image_arr = np .full ((height , weight , 4 ), [0 , 0 , 0 , 255 ], np .uint8 )
913916 for annotation in self .annotations ["instances" ]:
914- if (not annotation .get ("className" )) or (not class_color_map .get (annotation ["className" ])):
917+ if (not annotation .get ("className" )) or (
918+ not class_color_map .get (annotation ["className" ])
919+ ):
915920 continue
916921 fill_color = * class_color_map [annotation ["className" ]], 255
917922 for part in annotation ["parts" ]:
@@ -2002,17 +2007,28 @@ def validate_limitations(self):
20022007 if self ._move :
20032008 if self ._from_project .uuid == self ._to_project .uuid :
20042009 if self ._from_folder .uuid == self ._to_folder .uuid :
2005- raise AppValidationException ("Cannot move image if source_project == destination_project." )
2010+ raise AppValidationException (
2011+ "Cannot move image if source_project == destination_project."
2012+ )
20062013 elif response .data .folder_limit .remaining_image_count < 1 :
2007- raise AppValidationException (constances .MOVE_FOLDER_LIMIT_ERROR_MESSAGE )
2014+ raise AppValidationException (
2015+ constances .MOVE_FOLDER_LIMIT_ERROR_MESSAGE
2016+ )
20082017 elif response .data .project_limit .remaining_image_count < 1 :
2009- raise AppValidationException (constances .MOVE_PROJECT_LIMIT_ERROR_MESSAGE )
2018+ raise AppValidationException (
2019+ constances .MOVE_PROJECT_LIMIT_ERROR_MESSAGE
2020+ )
20102021 else :
20112022 if response .data .folder_limit .remaining_image_count < 1 :
20122023 raise AppValidationException (constances .COPY_FOLDER_LIMIT_ERROR_MESSAGE )
20132024 if response .data .project_limit .remaining_image_count < 1 :
2014- raise AppValidationException (constances .COPY_PROJECT_LIMIT_ERROR_MESSAGE )
2015- if response .data .super_user_limit and response .data .super_user_limit .remaining_image_count < 1 :
2025+ raise AppValidationException (
2026+ constances .COPY_PROJECT_LIMIT_ERROR_MESSAGE
2027+ )
2028+ if (
2029+ response .data .super_user_limit
2030+ and response .data .super_user_limit .remaining_image_count < 1
2031+ ):
20162032 raise AppValidationException (constances .COPY_SUPER_LIMIT_ERROR_MESSAGE )
20172033
20182034 @property
@@ -2689,6 +2705,8 @@ def execute(self):
26892705 else :
26902706 from_s3 = None
26912707
2708+ for _ in range (len (annotations_to_upload ) - len (response .data .images )):
2709+ yield
26922710 with concurrent .futures .ThreadPoolExecutor (
26932711 max_workers = self .MAX_WORKERS
26942712 ) as executor :
@@ -2720,7 +2738,6 @@ def execute(self):
27202738 failed_annotations = [
27212739 annotation .path for annotation in failed_annotations
27222740 ]
2723-
27242741 self ._response .data = (
27252742 uploaded_annotations ,
27262743 failed_annotations ,
@@ -2732,42 +2749,41 @@ def execute(self):
27322749 def upload_to_s3 (
27332750 self , image_id : int , image_info , bucket , from_s3 , image_id_name_map
27342751 ):
2735- if from_s3 :
2736- file = io .BytesIO ()
2737- s3_object = from_s3 .Object (
2738- self ._client_s3_bucket , image_id_name_map [image_id ].path
2739- )
2740- s3_object .download_fileobj (file )
2741- file .seek (0 )
2742- annotation_json = json .load (file )
2743- else :
2744- annotation_json = json .load (open (image_id_name_map [image_id ].path ))
2745-
2746- self .fill_classes_data (annotation_json )
2747-
2748- if not self ._is_valid_json (annotation_json ):
2749- logger .warning (f"Invalid json { image_id_name_map [image_id ].path } " )
2750- return image_id_name_map [image_id ], False
2751- bucket .put_object (
2752- Key = image_info ["annotation_json_path" ], Body = json .dumps (annotation_json ),
2753- )
2754- if self ._project .project_type == constances .ProjectType .PIXEL .value :
2755- mask_filename = (
2756- image_id_name_map [image_id ].name + constances .ANNOTATION_MASK_POSTFIX
2757- )
2752+ try :
27582753 if from_s3 :
27592754 file = io .BytesIO ()
27602755 s3_object = from_s3 .Object (
2761- self ._client_s3_bucket , f" { self . _folder_path } / { mask_filename } "
2756+ self ._client_s3_bucket , image_id_name_map [ image_id ]. path
27622757 )
27632758 s3_object .download_fileobj (file )
27642759 file .seek (0 )
2760+ annotation_json = json .load (file )
27652761 else :
2766- with open (f"{ self ._folder_path } /{ mask_filename } " , "rb" ) as mask_file :
2767- file = io .BytesIO (mask_file .read ())
2768-
2769- bucket .put_object (Key = image_info ["annotation_bluemap_path" ], Body = file )
2770- return image_id_name_map [image_id ], True
2762+ annotation_json = json .load (open (image_id_name_map [image_id ].path ))
2763+ self .fill_classes_data (annotation_json )
2764+ if not self ._is_valid_json (annotation_json ):
2765+ logger .warning (f"Invalid json { image_id_name_map [image_id ].path } " )
2766+ return image_id_name_map [image_id ], False
2767+ bucket .put_object (
2768+ Key = image_info ["annotation_json_path" ],
2769+ Body = json .dumps (annotation_json ),
2770+ )
2771+ if self ._project .project_type == constances .ProjectType .PIXEL .value :
2772+ mask_path = image_id_name_map [image_id ].path .replace (
2773+ "___pixel.json" , constances .ANNOTATION_MASK_POSTFIX
2774+ )
2775+ if from_s3 :
2776+ file = io .BytesIO ()
2777+ s3_object = from_s3 .Object (self ._client_s3_bucket , mask_path )
2778+ s3_object .download_fileobj (file )
2779+ file .seek (0 )
2780+ else :
2781+ with open (mask_path , "rb" ) as mask_file :
2782+ file = io .BytesIO (mask_file .read ())
2783+ bucket .put_object (Key = image_info ["annotation_bluemap_path" ], Body = file )
2784+ return image_id_name_map [image_id ], True
2785+ except Exception as _ :
2786+ return image_id_name_map [image_id ], False
27712787
27722788 def report_missing_data (self ):
27732789 if self .missing_classes :
0 commit comments