3434 fill_class_and_attribute_ids , get_annotation_classes_name_to_id ,
3535 search_annotation_classes
3636)
37- from .images import search_images
37+ from .images import get_image_metadata , search_images
3838from .project_api import get_project_metadata_bare
3939from .users import get_team_contributor_metadata
4040
@@ -1171,27 +1171,41 @@ def __upload_annotations_thread(
11711171 from_s3 = from_session .resource ('s3' )
11721172
11731173 for i in range (start_index , end_index , NUM_TO_SEND ):
1174- data = { "project_id" : project_id , "team_id" : team_id , "names" : []}
1174+ names = []
11751175 for j in range (i , i + NUM_TO_SEND ):
11761176 if j >= end_index :
11771177 break
11781178 image_name = anns_filenames [j ][:- len_postfix_json ]
1179- data ["names" ].append (image_name )
1179+ names .append (image_name )
1180+ try :
1181+ metadatas = get_image_metadata ({"id" : project_id }, names , False )
1182+ except SABaseException :
1183+ metadatas = []
1184+ names_in_metadatas = [metadata ["name" ] for metadata in metadatas ]
1185+ if len (names ) < len (metadatas ):
1186+ for name in names :
1187+ if name not in names_in_metadatas :
1188+ ann_path = Path (folder_path ) / (name + postfix_json )
1189+ missing_images [thread_id ].append (ann_path )
1190+ logger .warning (
1191+ "Couldn't find image %s for annotation upload" , ann_path
1192+ )
1193+ data = {
1194+ "project_id" : project_id ,
1195+ "team_id" : team_id ,
1196+ "ids" : [metadata ["id" ] for metadata in metadatas ]
1197+ }
11801198 response = _api .send_request (
11811199 req_type = 'POST' ,
11821200 path = '/images/getAnnotationsPathsAndTokens' ,
11831201 json_req = data
11841202 )
1185- #TODO: will res["images"] = [{image_name: {annotation_json_path:, annotation_blue_map_path:}}, ]
1203+ if not response .ok :
1204+ logger .warning (
1205+ "Couldn't get token upload annotations %s" , response .text
1206+ )
1207+ continue
11861208 res = response .json ()
1187- if len (res ["images" ]) < len (data ["names" ]):
1188- for name in data ["names" ]:
1189- if name not in res ["images" ]:
1190- ann_path = Path (folder_path ) / (name + postfix_json )
1191- missing_images [thread_id ].append (ann_path )
1192- logger .warning (
1193- "Couldn't find image %s for annotation upload" , ann_path
1194- )
11951209 aws_creds = res ["creds" ]
11961210 s3_session = boto3 .Session (
11971211 aws_access_key_id = aws_creds ['accessKeyId' ],
@@ -1201,7 +1215,7 @@ def __upload_annotations_thread(
12011215 s3_resource = s3_session .resource ('s3' )
12021216 bucket = s3_resource .Bucket (aws_creds ["bucket" ])
12031217
1204- for image_name , image_path in res ['images' ].items ():
1218+ for image_name , image_info in res ['images' ].items ():
12051219 json_filename = image_name + postfix_json
12061220 if from_s3_bucket is None :
12071221 full_path = Path (folder_path ) / json_filename
@@ -1225,9 +1239,10 @@ def __upload_annotations_thread(
12251239 annotation_json , annotation_classes_dict
12261240 )
12271241 bucket .put_object (
1228- Key = image_path + postfix_json , Body = json .dumps (annotation_json )
1242+ Key = image_info ["annotation_json_path" ],
1243+ Body = json .dumps (annotation_json )
12291244 )
1230- if project_type != "Vector " :
1245+ if project_type == "Pixel " :
12311246 mask_filename = image_name + postfix_mask
12321247 if from_s3_bucket is None :
12331248 with open (Path (folder_path ) / mask_filename , 'rb' ) as fin :
@@ -1239,7 +1254,9 @@ def __upload_annotations_thread(
12391254 )
12401255 from_s3_object .download_fileobj (file )
12411256 file .seek (0 )
1242- bucket .put_object (Key = image_path + postfix_mask , Body = file )
1257+ bucket .put_object (
1258+ Key = image_info ["annotation_bluemap_path" ], Body = file
1259+ )
12431260 uploaded [thread_id ].append (full_path )
12441261
12451262
0 commit comments