@@ -15,6 +15,7 @@ class Annotation(BaseModel):
1515 instanceId : int
1616 type : str
1717 className : Optional [str ]
18+ classId : Optional [int ]
1819 x : Optional [Any ]
1920 y : Optional [Any ]
2021 points : Optional [Dict ]
@@ -57,6 +58,7 @@ def get_frame(self, frame_no: int):
5758 def _interpolate (
5859 self ,
5960 class_name : str ,
61+ class_id : int ,
6062 from_frame : int ,
6163 to_frame : int ,
6264 data : dict ,
@@ -87,6 +89,7 @@ def _interpolate(
8789 instanceId = instance_id ,
8890 type = annotation_type ,
8991 className = class_name ,
92+ classId = class_id ,
9093 attributes = data ["attributes" ],
9194 keyframe = False ,
9295 ** tmp_data
@@ -105,23 +108,21 @@ def pairwise(data: list):
105108 return zip (a , b )
106109
107110 def get_median (self , annotations : List [dict ]) -> dict :
108- if len (annotations ) = = 1 :
111+ if len (annotations ) > = 1 :
109112 return annotations [0 ]
110- first_annotations = annotations [:1 ][0 ]
111- median = (
112- first_annotations ["timestamp" ] // self .ratio
113- ) * self .ratio + self .ratio / 2
114- median_annotation = first_annotations
115- distance = abs (median - first_annotations ["timestamp" ])
116- for annotation in annotations [1 :]:
117- annotation_distance = abs (median - annotation ["timestamp" ])
118- if annotation_distance < distance :
119- distance = annotation_distance
120- median_annotation = annotation
121- return median_annotation
122-
123- def calculate_sped (self , from_frame , to_frame ):
124- pass
113+ ## Let's just leave the code for reference.
114+ # first_annotations = annotations[:1][0]
115+ # median = (
116+ # first_annotations["timestamp"] // self.ratio
117+ # ) * self.ratio + self.ratio / 2
118+ # median_annotation = first_annotations
119+ # distance = abs(median - first_annotations["timestamp"])
120+ # for annotation in annotations[1:]:
121+ # annotation_distance = abs(median - annotation["timestamp"])
122+ # if annotation_distance < distance:
123+ # distance = annotation_distance
124+ # median_annotation = annotation
125+ # return median_annotation
125126
126127 @staticmethod
127128 def merge_first_frame (frames_mapping ):
@@ -141,6 +142,7 @@ def _interpolate_frames(
141142 to_frame_no ,
142143 annotation_type ,
143144 class_name ,
145+ class_id ,
144146 instance_id ,
145147 ):
146148 steps = None
@@ -171,6 +173,7 @@ def _interpolate_frames(
171173 ]
172174 return self ._interpolate (
173175 class_name = class_name ,
176+ class_id = class_id ,
174177 from_frame = from_frame_no ,
175178 to_frame = to_frame_no ,
176179 data = from_frame ,
@@ -184,6 +187,7 @@ def _process(self):
184187 instance_id = next (self .id_generator )
185188 annotation_type = instance ["meta" ]["type" ]
186189 class_name = instance ["meta" ].get ("className" )
190+ class_id = instance ["meta" ].get ("classId" , - 1 )
187191 for parameter in instance ["parameters" ]:
188192 frames_mapping = defaultdict (list )
189193 interpolated_frames = {}
@@ -207,6 +211,7 @@ def _process(self):
207211 to_frame = to_frame ,
208212 to_frame_no = to_frame_no ,
209213 class_name = class_name ,
214+ class_id = class_id ,
210215 annotation_type = annotation_type ,
211216 instance_id = instance_id ,
212217 )
@@ -222,6 +227,7 @@ def _process(self):
222227 instanceId = instance_id ,
223228 type = annotation_type ,
224229 className = class_name ,
230+ classId = class_id ,
225231 x = frame .get ("x" ),
226232 y = frame .get ("y" ),
227233 points = frame .get ("points" ),
@@ -234,6 +240,7 @@ def _process(self):
234240 instanceId = instance_id ,
235241 type = annotation_type ,
236242 className = class_name ,
243+ classId = class_id ,
237244 x = median .get ("x" ),
238245 y = median .get ("y" ),
239246 points = median .get ("points" ),
0 commit comments