Skip to content

Commit 5550937

Browse files
authored
Merge pull request #485 from superannotateai/1247_get_annotations_per_frame
1247 get annotations per frame
2 parents 36c12ae + 248d826 commit 5550937

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/superannotate/lib/app/analytics/aggregators.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ def aggregate_annotations_as_df(self):
172172
elif self.project_type == constances.ProjectType.DOCUMENT.name:
173173
return self.aggregate_document_annotations_as_df(annotation_paths)
174174

175+
def __add_attributes_to_raws(self, raws, attributes, element_raw):
176+
for attribute_id, attribute in enumerate(attributes):
177+
attribute_raw = copy.copy(element_raw)
178+
attribute_raw.attributeId = attribute_id
179+
attribute_raw.attributeGroupName = attribute.get(
180+
"groupName"
181+
)
182+
attribute_raw.attributeName = attribute.get("name")
183+
raws.append(attribute_raw)
184+
if not attributes:
185+
raws.append(element_raw)
186+
187+
return raws
188+
175189
def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
176190
raws = []
177191
for annotation_path in annotation_paths:
@@ -226,6 +240,9 @@ def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
226240
)
227241
instance_raw.pointLabels = instance["meta"].get("pointLabels")
228242
parameters = instance.get("parameters", [])
243+
if instance_raw.type == 'tag':
244+
attributes = instance["meta"].get("attributes",[])
245+
raws = self.__add_attributes_to_raws(raws, attributes, instance_raw)
229246
for parameter_id, parameter in enumerate(parameters):
230247
parameter_raw = copy.copy(instance_raw)
231248
parameter_raw.parameterId = parameter_id
@@ -237,16 +254,7 @@ def aggregate_video_annotations_as_df(self, annotation_paths: List[str]):
237254
timestamp_raw.timestampId = timestamp_id
238255
timestamp_raw.meta = self.MAPPERS[instance_type](timestamp)
239256
attributes = timestamp.get("attributes", [])
240-
for attribute_id, attribute in enumerate(attributes):
241-
attribute_raw = copy.copy(timestamp_raw)
242-
attribute_raw.attributeId = attribute_id
243-
attribute_raw.attributeGroupName = attribute.get(
244-
"groupName"
245-
)
246-
attribute_raw.attributeName = attribute.get("name")
247-
raws.append(attribute_raw)
248-
if not attributes:
249-
raws.append(timestamp_raw)
257+
raws = self.__add_attributes_to_raws(raws, attributes, timestamp_raw)
250258
if not timestamps:
251259
raws.append(parameter_raw)
252260
if not parameters:

src/superannotate/lib/core/video_convertor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def pairwise(data: list):
9999
next(b, None)
100100
return zip(a, b)
101101

102+
102103
def get_median(self, annotations: List[dict]) -> dict:
103104
if len(annotations) >= 1:
104105
return annotations[0]
@@ -180,14 +181,15 @@ def _process(self):
180181
annotation_type = instance["meta"]["type"]
181182
class_name = instance["meta"].get("className")
182183
class_id = instance["meta"].get("classId", -1)
183-
for parameter in instance["parameters"]:
184+
for parameter in instance.get("parameters", []):
184185
frames_mapping = defaultdict(list)
185186
interpolated_frames = {}
186187
for timestamp in parameter["timestamps"]:
187188
frames_mapping[
188189
int(math.ceil(timestamp["timestamp"] / self.ratio))
189190
].append(timestamp)
190191
frames_mapping = self.merge_first_frame(frames_mapping)
192+
191193
for from_frame_no, to_frame_no in self.pairwise(sorted(frames_mapping)):
192194
last_frame_no = to_frame_no
193195
from_frame, to_frame = (
@@ -227,7 +229,9 @@ def _process(self):
227229
keyframe=True,
228230
)
229231
if frames_mapping and not interpolated_frames:
230-
median = self.get_median(frames_mapping[1])
232+
key = set(frames_mapping.keys()).pop()
233+
median = self.get_median(frames_mapping[key])
234+
231235
interpolated_frames[1] = Annotation(
232236
instanceId=instance_id,
233237
type=annotation_type,

0 commit comments

Comments
 (0)