99import lib .core as constances
1010import pandas as pd
1111from lib .app .exceptions import AppException
12- from lib .core import ATTACHED_VIDEO_ANNOTATION_POSTFIX
1312from lib .core import PIXEL_ANNOTATION_POSTFIX
1413from lib .core import VECTOR_ANNOTATION_POSTFIX
1514from superannotate .logger import get_default_logger
1615
1716logger = get_default_logger ()
1817
18+
1919@dataclass
2020class ImageRowData :
2121 itemName : str = None
@@ -50,6 +50,7 @@ class ImageRowData:
5050 commentResolved : str = None
5151 tag : str = None
5252
53+
5354@dataclass
5455class VideoRawData :
5556 itemName : str = None
@@ -135,9 +136,9 @@ class DataAggregator:
135136 ),
136137 "tag" : lambda annotation : None ,
137138 "mask" : lambda annotation : {"parts" : annotation ["parts" ]},
138- "template" : lambda annotation : None ,
139+ "template" : lambda annotation : None ,
139140 "rbbox" : lambda annotation : annotation ["points" ],
140- "comment_inst" : lambda annotation : annotation ["points" ]
141+ "comment_inst" : lambda annotation : annotation ["points" ],
141142 }
142143
143144 def __init__ (
@@ -204,18 +205,16 @@ def aggregate_annotations_as_df(self):
204205 self .check_classes_path ()
205206 annotation_paths = self .get_annotation_paths ()
206207
207-
208208 if self .project_type in (
209209 constances .ProjectType .VECTOR ,
210- constances .ProjectType .PIXEL
210+ constances .ProjectType .PIXEL ,
211211 ):
212212 return self .aggregate_image_annotations_as_df (annotation_paths )
213213 elif self .project_type is constances .ProjectType .VIDEO :
214214 return self .aggregate_video_annotations_as_df (annotation_paths )
215215 elif self .project_type is constances .ProjectType .DOCUMENT :
216216 return self .aggregate_document_annotations_as_df (annotation_paths )
217217
218-
219218 def __add_attributes_to_raws (self , raws , attributes , element_raw ):
220219 for attribute_id , attribute in enumerate (attributes ):
221220 attribute_raw = copy .copy (element_raw )
@@ -388,10 +387,10 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
388387 for annotation_path in annotations_paths :
389388 row_data = ImageRowData ()
390389 annotation_json = None
391- with open (annotation_path , 'r' ) as fp :
390+ with open (annotation_path ) as fp :
392391 annotation_json = json .load (fp )
393392 parts = Path (annotation_path ).name .split (self ._annotation_suffix )
394- row_data = self .__fill_image_metadata (row_data , annotation_json [' metadata' ])
393+ row_data = self .__fill_image_metadata (row_data , annotation_json [" metadata" ])
395394 annotation_instance_id = 0
396395
397396 # include comments
@@ -408,7 +407,7 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
408407 tag_row .rag = tag
409408 rows .append (tag_row )
410409
411- #Instances
410+ # Instances
412411 for idx , annotation in enumerate (annotation_json ["instances" ]):
413412 instance_row = copy .copy (row_data )
414413 annotation_type = annotation .get ("type" , "mask" )
@@ -462,7 +461,8 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
462461 attribute_name
463462 not in class_group_name_to_values [annotation_class_name ][
464463 attribute_group
465- ] and group_id not in freestyle_attributes
464+ ]
465+ and group_id not in freestyle_attributes
466466 ):
467467 logger .warning (
468468 f"Annotation class group value { attribute_name } not in classes json. Skipping."
@@ -473,7 +473,6 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
473473 attribute_row .attributeGroupName = attribute_group
474474 attribute_row .attributeName = attribute_name
475475
476-
477476 rows .append (attribute_row )
478477 num_added += 1
479478
@@ -486,7 +485,7 @@ def aggregate_image_annotations_as_df(self, annotations_paths: List[str]):
486485
487486 @staticmethod
488487 def __fill_image_metadata (raw_data , metadata ):
489- raw_data .itemName = metadata .get (' name' )
488+ raw_data .itemName = metadata .get (" name" )
490489 raw_data .itemHeight = metadata .get ("height" )
491490 raw_data .itemWidth = metadata .get ("width" )
492491 raw_data .itemStatus = metadata .get ("status" )
0 commit comments