@@ -753,13 +753,17 @@ def get_image_annotations(project, image_name, project_type=None):
753753 raise SABaseException (response .status_code , response .text )
754754 res_json = response .json ()
755755 fill_class_and_attribute_names (res_json , annotation_classes_dict )
756- url = res ["pixelSave" ]["url" ]
757- annotation_mask_filename = url .rsplit ('/' , 1 )[- 1 ]
758- headers = res ["pixelSave" ]["headers" ]
759- response = requests .get (url = url , headers = headers )
760- if not response .ok :
761- raise SABaseException (response .status_code , response .text )
762- mask = io .BytesIO (response .content )
756+ if len (res_json ["instances" ]) != 0 :
757+ url = res ["pixelSave" ]["url" ]
758+ annotation_mask_filename = url .rsplit ('/' , 1 )[- 1 ]
759+ headers = res ["pixelSave" ]["headers" ]
760+ response = requests .get (url = url , headers = headers )
761+ if not response .ok :
762+ raise SABaseException (response .status_code , response .text )
763+ mask = io .BytesIO (response .content )
764+ else :
765+ mask = None
766+ annotation_mask_filename = None
763767 return {
764768 "annotation_json" : res_json ,
765769 "annotation_json_filename" : annotation_json_filename ,
@@ -800,11 +804,14 @@ def download_image_annotations(project, image_name, local_dir_path):
800804 else :
801805 with open (json_path , "w" ) as f :
802806 json .dump (annotation ["annotation_json" ], f , indent = 4 )
803- mask_path = Path (local_dir_path
804- ) / annotation ["annotation_mask_filename" ]
807+ if annotation ["annotation_mask_filename" ] is not None :
808+ mask_path = Path (local_dir_path
809+ ) / annotation ["annotation_mask_filename" ]
810+ with open (mask_path , "wb" ) as f :
811+ f .write (annotation ["annotation_mask" ].getbuffer ())
812+ else :
813+ mask_path = None
805814 return_filepaths .append (str (mask_path ))
806- with open (mask_path , "wb" ) as f :
807- f .write (annotation ["annotation_mask" ].getbuffer ())
808815
809816 return tuple (return_filepaths )
810817
0 commit comments