|
48 | 48 | NDVideoMasks,
|
49 | 49 | )
|
50 | 50 | from .relationship import NDRelationship
|
51 |
| -from .utils.temporal_processor import VideoTemporalProcessor, AudioTemporalProcessor |
| 51 | +from .utils.temporal_processor import AudioTemporalProcessor |
52 | 52 |
|
53 | 53 | AnnotationType = Union[
|
54 | 54 | NDObjectType,
|
@@ -130,14 +130,41 @@ def _get_segment_frame_ranges(
|
130 | 130 | def _create_video_annotations(
|
131 | 131 | cls, label: Label
|
132 | 132 | ) -> Generator[Union[NDChecklistSubclass, NDRadioSubclass], None, None]:
|
133 |
| - # Handle video mask annotations separately (special case) |
| 133 | + video_annotations = defaultdict(list) |
134 | 134 | 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): |
136 | 142 | 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) |
141 | 168 |
|
142 | 169 | @classmethod
|
143 | 170 | def _create_audio_annotations(
|
|
0 commit comments