@@ -183,10 +183,17 @@ def aggregate_annotations_as_df(
183183 )
184184 classes_json = json .load (open (classes_path ))
185185 class_name_to_color = {}
186+ class_group_name_to_values = {}
186187 for annotation_class in classes_json :
187188 name = annotation_class ["name" ]
188189 color = annotation_class ["color" ]
189190 class_name_to_color [name ] = color
191+ class_group_name_to_values [name ] = {}
192+ for attribute_group in annotation_class ["attribute_groups" ]:
193+ class_group_name_to_values [name ][attribute_group ["name" ]] = []
194+ for attribute in attribute_group ["attributes" ]:
195+ class_group_name_to_values [name ][attribute_group ["name" ]
196+ ].append (attribute ["name" ])
190197
191198 def __append_annotation (annotation_dict ):
192199 for annotation_key in annotation_data :
@@ -258,10 +265,12 @@ def __get_image_metadata(image_name, annotations):
258265 continue
259266 annotation_instance_id += 1
260267 annotation_class_name = annotation .get ("className" )
261- if annotation_class_name is None :
262- raise SABaseException (
263- 0 , "Annotation class not found in classes.json"
268+ if annotation_class_name is None or annotation_class_name not in class_name_to_color :
269+ logger .warning (
270+ "Annotation class %s not found in classes json. Skipping." ,
271+ annotation_class_name
264272 )
273+ continue
265274 annotation_class_color = class_name_to_color [annotation_class_name ]
266275 annotation_group_id = annotation .get ("groupId" )
267276 annotation_locked = annotation .get ("locked" )
@@ -332,37 +341,50 @@ def __get_image_metadata(image_name, annotations):
332341 }
333342 annotation_dict .update (image_metadata )
334343 __append_annotation (annotation_dict )
335-
336- for attribute in attributes :
337-
338- attribute_group = attribute .get ("groupName" )
339- attribute_name = attribute .get ('name' )
340- annotation_dict = {
341- "imageName" : image_name ,
342- "instanceId" : annotation_instance_id ,
343- "className" : annotation_class_name ,
344- "attributeGroupName" : attribute_group ,
345- "attributeName" : attribute_name ,
346- "type" : annotation_type ,
347- "locked" : annotation_locked ,
348- "visible" : annotation_visible ,
349- "trackingId" : annotation_tracking_id ,
350- "meta" : annotation_meta ,
351- "error" : annotation_error ,
352- "probability" : annotation_probability ,
353- "pointLabels" : annotation_point_labels ,
354- "classColor" : annotation_class_color ,
355- "groupId" : annotation_group_id ,
356- "createdAt" : annotation_created_at ,
357- "creatorRole" : annotation_creator_role ,
358- "creatorEmail" : annotation_creator_email ,
359- "creationType" : annotation_creation_type ,
360- "updatedAt" : annotation_updated_at ,
361- "updatorRole" : annotation_updator_role ,
362- "updatorEmail" : annotation_updator_email
363- }
364- annotation_dict .update (image_metadata )
365- __append_annotation (annotation_dict )
344+ else :
345+ for attribute in attributes :
346+ attribute_group = attribute .get ("groupName" )
347+ attribute_name = attribute .get ('name' )
348+ if attribute_group not in class_group_name_to_values [
349+ annotation_class_name ]:
350+ logger .warning (
351+ "Annotation class group %s not in classes json. Skipping." ,
352+ attribute_group
353+ )
354+ continue
355+ if attribute_name not in class_group_name_to_values [
356+ annotation_class_name ][attribute_group ]:
357+ logger .warning (
358+ "Annotation class group value %s not in classes json. Skipping." ,
359+ attribute_name
360+ )
361+ continue
362+ annotation_dict = {
363+ "imageName" : image_name ,
364+ "instanceId" : annotation_instance_id ,
365+ "className" : annotation_class_name ,
366+ "attributeGroupName" : attribute_group ,
367+ "attributeName" : attribute_name ,
368+ "type" : annotation_type ,
369+ "locked" : annotation_locked ,
370+ "visible" : annotation_visible ,
371+ "trackingId" : annotation_tracking_id ,
372+ "meta" : annotation_meta ,
373+ "error" : annotation_error ,
374+ "probability" : annotation_probability ,
375+ "pointLabels" : annotation_point_labels ,
376+ "classColor" : annotation_class_color ,
377+ "groupId" : annotation_group_id ,
378+ "createdAt" : annotation_created_at ,
379+ "creatorRole" : annotation_creator_role ,
380+ "creatorEmail" : annotation_creator_email ,
381+ "creationType" : annotation_creation_type ,
382+ "updatedAt" : annotation_updated_at ,
383+ "updatorRole" : annotation_updator_role ,
384+ "updatorEmail" : annotation_updator_email
385+ }
386+ annotation_dict .update (image_metadata )
387+ __append_annotation (annotation_dict )
366388
367389 df = pd .DataFrame (annotation_data )
368390
0 commit comments