@@ -297,23 +297,25 @@ def download_annotation_classes_json(project, folder):
297297
298298def fill_class_and_attribute_names (annotations_json , annotation_classes_dict ):
299299 for r in annotations_json ["instances" ]:
300- if "classId" in r and r ["classId" ] in annotation_classes_dict :
301- r ["className" ] = annotation_classes_dict [r ["classId" ]]["name" ]
302- if "attributes" in r :
303- for attribute in r ["attributes" ]:
304- if "groupId" in attribute and "id" in attribute :
305- if attribute ["groupId" ] in annotation_classes_dict [
306- r ["classId" ]]["attribute_groups" ]:
307- attribute ["groupName" ] = annotation_classes_dict [
308- r ["classId" ]]["attribute_groups" ][
309- attribute ["groupId" ]]["name" ]
310- if attribute ["id" ] in annotation_classes_dict [
311- r ["classId" ]]["attribute_groups" ][
312- attribute ["groupId" ]]["attributes" ]:
313- attribute ["name" ] = annotation_classes_dict [
314- r ["classId" ]]["attribute_groups" ][
315- attribute ["groupId" ]]["attributes" ][
316- attribute ["id" ]]
300+ if "classId" not in r or r ["classId" ] not in annotation_classes_dict :
301+ continue
302+ r ["className" ] = annotation_classes_dict [r ["classId" ]]["name" ]
303+ if "attributes" not in r :
304+ continue
305+ for attribute in r ["attributes" ]:
306+ if "groupId" not in attribute or "id" not in attribute :
307+ continue
308+ if attribute ["groupId" ] not in annotation_classes_dict [
309+ r ["classId" ]]["attribute_groups" ]:
310+ continue
311+ attribute ["groupName" ] = annotation_classes_dict [
312+ r ["classId" ]]["attribute_groups" ][attribute ["groupId" ]]["name" ]
313+ if attribute ["id" ] not in annotation_classes_dict [r ["classId" ]][
314+ "attribute_groups" ][attribute ["groupId" ]]["attributes" ]:
315+ continue
316+ attribute ["name" ] = annotation_classes_dict [
317+ r ["classId" ]]["attribute_groups" ][
318+ attribute ["groupId" ]]["attributes" ][attribute ["id" ]]
317319
318320
319321def fill_class_and_attribute_ids (annotation_json , annotation_classes_dict ):
@@ -330,28 +332,27 @@ def fill_class_and_attribute_ids(annotation_json, annotation_classes_dict):
330332 class_id = annotation_classes_dict [annotation_class_name ]["id" ]
331333 ann ["classId" ] = class_id
332334 for attribute in ann ["attributes" ]:
333- if attribute ["groupName" ] in annotation_classes_dict [
335+ if attribute ["groupName" ] not in annotation_classes_dict [
334336 annotation_class_name ]["attribute_groups" ]:
335- attribute ["groupId" ] = annotation_classes_dict [
336- annotation_class_name ]["attribute_groups" ][
337- attribute ["groupName" ]]["id" ]
338- else :
339337 logger .warning (
340338 "Couldn't find annotation group %s" , attribute ["groupName" ]
341339 )
342340 continue
343- if attribute ["name" ] in annotation_classes_dict [
341+ attribute ["groupId" ] = annotation_classes_dict [
342+ annotation_class_name ]["attribute_groups" ][
343+ attribute ["groupName" ]]["id" ]
344+ if attribute ["name" ] not in annotation_classes_dict [
344345 annotation_class_name ]["attribute_groups" ][
345346 attribute ["groupName" ]]["attributes" ]:
346- attribute ["id" ] = annotation_classes_dict [
347- annotation_class_name ]["attribute_groups" ][
348- attribute ["groupName" ]]["attributes" ][attribute ["name" ]]
349- else :
350347 logger .warning (
351348 "Couldn't find annotation name %s in annotation group %s" ,
352349 attribute ["name" ], attribute ["groupName" ]
353350 )
354351 del attribute ["groupId" ]
352+ continue
353+ attribute ["id" ] = annotation_classes_dict [annotation_class_name ][
354+ "attribute_groups" ][attribute ["groupName" ]]["attributes" ][
355+ attribute ["name" ]]
355356
356357
357358def check_annotation_json (annotation_json ):
0 commit comments