1515
1616from .metric import NDScalarMetric , NDMetricAnnotation , NDConfusionMatrixMetric
1717from .classification import NDChecklistSubclass , NDClassification , NDClassificationType , NDRadioSubclass
18- from .objects import NDObject , NDObjectType
18+ from .objects import NDObject , NDObjectType , NDFrameObjectType , NDSegments
1919
2020
2121class NDLabel (BaseModel ):
2222 annotations : List [Union [NDObjectType , NDClassificationType ,
23- NDConfusionMatrixMetric , NDScalarMetric ]]
23+ NDConfusionMatrixMetric , NDScalarMetric ,
24+ NDSegments ]]
2425
2526 def to_common (self ) -> LabelGenerator :
2627 grouped_annotations = defaultdict (list )
2728 for annotation in self .annotations :
2829 grouped_annotations [annotation .data_row .id ].append (annotation )
2930 return LabelGenerator (
3031 data = self ._generate_annotations (grouped_annotations ))
32+ # c = LabelGenerator(data=self._generate_annotations(grouped_annotations))
33+ # print(next(c), "Wefwefweefw\n")
3134
3235 @classmethod
3336 def from_common (cls ,
3437 data : LabelCollection ) -> Generator ["NDLabel" , None , None ]:
3538 for label in data :
36- # print(f"label in data:{label}")
3739 yield from cls ._create_non_video_annotations (label )
3840 yield from cls ._create_video_annotations (label )
3941
4042 def _generate_annotations (
41- self , grouped_annotations : Dict [str , List [Union [NDObjectType ,
42- NDClassificationType ,
43- NDConfusionMatrixMetric ,
44- NDScalarMetric ]]]
43+ self ,
44+ grouped_annotations : Dict [str ,
45+ List [Union [NDObjectType , NDClassificationType ,
46+ NDConfusionMatrixMetric ,
47+ NDScalarMetric , NDSegments ]]]
4548 ) -> Generator [Label , None , None ]:
4649 for data_row_id , annotations in grouped_annotations .items ():
4750 annots = []
4851 for annotation in annotations :
52+ if isinstance (annotation , NDSegments ):
53+ # b = NDSegments.to_common(annotation, annotation.schema_id)
54+ # print(type(b), b)
55+ annots .extend (
56+ NDSegments .to_common (annotation , annotation .schema_id ))
4957
50- if isinstance (annotation , NDObjectType .__args__ ):
58+ elif isinstance (annotation , NDObjectType .__args__ ):
5159 annots .append (NDObject .to_common (annotation ))
52- #TODO: have a check on if the return type needs to extend or not
5360 elif isinstance (annotation , NDClassificationType .__args__ ):
5461 annots .extend (NDClassification .to_common (annotation ))
5562 elif isinstance (annotation ,
@@ -58,7 +65,7 @@ def _generate_annotations(
5865 else :
5966 raise TypeError (
6067 f"Unsupported annotation. { type (annotation )} " )
61-
68+ # print(type(annots[0]), annots[0])
6269 data = self ._infer_media_type (annotations )(uid = data_row_id )
6370 yield Label (annotations = annots , data = data )
6471
@@ -115,31 +122,7 @@ def _create_video_annotations(
115122 if annotation .keyframe and start_frame <= annotation .frame <= end_frame :
116123 segment .append (annotation )
117124 segments .append (segment )
118-
119- print (segments [0 ], "\n " )
120- print (segments [1 ], "\n " )
121- print (consecutive_frames )
122125 yield NDObject .from_common (segments , label .data )
123- # segments = []
124- # seg_frames = []
125- # for cframes in consecutive_frames:
126- # seg_frames.append(cframes[0])
127- # seg_frames.append(cframes[1])
128- # print(seg_frames)
129- # for annotation in annotation_group:
130- # if annotation.frame in seg_frames:
131- # segments.append(annotation)
132- # # if annotation.keyframe:
133- # # segments.append(annotation)
134- # # print(consecutive_frames)
135- # #TODO: current issue is that the way the code is written doesn't account for
136- # #which frames are consecutive. maybe we should just have list of segments
137- # annotations = []
138- # for annotation in segments:
139- # annotations.append(
140- # NDObject.from_common(annotation, label.data))
141- # yield annotations[0]
142- # yield {}
143126
144127 @classmethod
145128 def _create_non_video_annotations (cls , label : Label ):
0 commit comments