Skip to content

Commit 8d9f9cd

Browse files
chore: cleanup
1 parent 1e12596 commit 8d9f9cd

File tree

2 files changed

+34
-44
lines changed

2 files changed

+34
-44
lines changed

libs/labelbox/src/labelbox/data/serialization/ndjson/label.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
NDVideoMasks,
4949
)
5050
from .relationship import NDRelationship
51-
from .utils.temporal_processor import VideoTemporalProcessor, AudioTemporalProcessor
51+
from .utils.temporal_processor import AudioTemporalProcessor
5252

5353
AnnotationType = Union[
5454
NDObjectType,
@@ -130,14 +130,41 @@ def _get_segment_frame_ranges(
130130
def _create_video_annotations(
131131
cls, label: Label
132132
) -> Generator[Union[NDChecklistSubclass, NDRadioSubclass], None, None]:
133-
# Handle video mask annotations separately (special case)
133+
video_annotations = defaultdict(list)
134134
for annot in label.annotations:
135-
if isinstance(annot, VideoMaskAnnotation):
135+
if isinstance(
136+
annot, (VideoClassificationAnnotation, VideoObjectAnnotation)
137+
):
138+
video_annotations[annot.feature_schema_id or annot.name].append(
139+
annot
140+
)
141+
elif isinstance(annot, VideoMaskAnnotation):
136142
yield NDObject.from_common(annotation=annot, data=label.data)
137-
138-
# Use temporal processor for video classifications and objects
139-
processor = VideoTemporalProcessor()
140-
yield from processor.process_annotations(label)
143+
144+
for annotation_group in video_annotations.values():
145+
segment_frame_ranges = cls._get_segment_frame_ranges(
146+
annotation_group
147+
)
148+
if isinstance(annotation_group[0], VideoClassificationAnnotation):
149+
annotation = annotation_group[0]
150+
frames_data = []
151+
for frames in segment_frame_ranges:
152+
frames_data.append({"start": frames[0], "end": frames[-1]})
153+
annotation.extra.update({"frames": frames_data})
154+
yield NDClassification.from_common(annotation, label.data)
155+
156+
elif isinstance(annotation_group[0], VideoObjectAnnotation):
157+
segments = []
158+
for start_frame, end_frame in segment_frame_ranges:
159+
segment = []
160+
for annotation in annotation_group:
161+
if (
162+
annotation.keyframe
163+
and start_frame <= annotation.frame <= end_frame
164+
):
165+
segment.append(annotation)
166+
segments.append(segment)
167+
yield NDObject.from_common(segments, label.data)
141168

142169
@classmethod
143170
def _create_audio_annotations(

libs/labelbox/src/labelbox/data/serialization/ndjson/utils/temporal_processor.py

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -138,40 +138,3 @@ def prepare_grouped_content(self, annotation_group: List) -> None:
138138
# Update the template annotation
139139
annotation_group[0].value = Text(answer=content_structure)
140140

141-
142-
class VideoTemporalProcessor(TemporalAnnotationProcessor):
143-
"""Processor for video temporal annotations - matches existing behavior"""
144-
145-
def get_annotation_types(self) -> tuple:
146-
from ....annotation_types.video import VideoClassificationAnnotation, VideoObjectAnnotation
147-
return (VideoClassificationAnnotation,), (VideoObjectAnnotation,)
148-
149-
def should_group_annotations(self, annotation_group: List) -> bool:
150-
"""Video always groups by segment ranges"""
151-
return True
152-
153-
def build_frame_data(self, annotation_group: List) -> List[Dict[str, Any]]:
154-
"""Build frame data using existing video segment logic"""
155-
from ..label import NDLabel # Import here to avoid circular import
156-
157-
segment_frame_ranges = NDLabel._get_segment_frame_ranges(annotation_group)
158-
return [{"start": frames[0], "end": frames[-1]} for frames in segment_frame_ranges]
159-
160-
def prepare_grouped_content(self, annotation_group: List) -> None:
161-
"""Video doesn't modify content - uses existing value"""
162-
pass
163-
164-
def _process_object_group(self, annotation_group, data):
165-
"""Video objects use segment-based processing"""
166-
from ..label import NDLabel
167-
168-
segment_frame_ranges = NDLabel._get_segment_frame_ranges(annotation_group)
169-
segments = []
170-
for start_frame, end_frame in segment_frame_ranges:
171-
segment = []
172-
for annotation in annotation_group:
173-
if (annotation.keyframe and
174-
start_frame <= annotation.frame <= end_frame):
175-
segment.append(annotation)
176-
segments.append(segment)
177-
yield NDObject.from_common(segments, data)

0 commit comments

Comments
 (0)