11from itertools import groupby
2+ from labelbox .data .annotation_types .metrics import ScalarMetric
3+
24from operator import itemgetter
35from typing import Dict , Generator , List , Tuple , Union
46from collections import defaultdict
1012from ...annotation_types .data import RasterData , TextData , VideoData
1113from ...annotation_types .label import Label
1214from ...annotation_types .ner import TextEntity
13- from .classification import NDChecklistSubclass , NDClassification , NDRadioSubclass , NDClassificationType
15+ from .metric import NDMetricAnnotation , NDMetricType
16+ from .classification import NDChecklistSubclass , NDClassification , NDClassificationType , NDRadioSubclass
1417from .objects import NDObject , NDObjectType
1518
1619
1720class NDLabel (BaseModel ):
18- annotations : List [Union [NDObjectType , NDClassificationType ]]
21+ annotations : List [Union [NDObjectType , NDClassificationType , NDMetricType ]]
1922
2023 def to_common (self ) -> LabelGenerator :
2124 grouped_annotations = defaultdict (list )
@@ -33,7 +36,8 @@ def from_common(cls,
3336
3437 def _generate_annotations (
3538 self , grouped_annotations : Dict [str , List [Union [NDObjectType ,
36- NDClassificationType ]]]
39+ NDClassificationType ,
40+ NDMetricType ]]]
3741 ) -> Generator [Label , None , None ]:
3842 for data_row_id , annotations in grouped_annotations .items ():
3943 annots = []
@@ -42,6 +46,8 @@ def _generate_annotations(
4246 annots .append (NDObject .to_common (annotation ))
4347 elif isinstance (annotation , NDClassificationType .__args__ ):
4448 annots .extend (NDClassification .to_common (annotation ))
49+ elif isinstance (annotation , NDMetricType ):
50+ annots .append (NDMetricAnnotation .to_common (annotation ))
4551 else :
4652 raise TypeError (
4753 f"Unsupported annotation. { type (annotation )} " )
@@ -99,6 +105,8 @@ def _create_non_video_annotations(cls, label: Label):
99105 yield NDClassification .from_common (annotation , label .data )
100106 elif isinstance (annotation , ObjectAnnotation ):
101107 yield NDObject .from_common (annotation , label .data )
108+ elif isinstance (annotation , ScalarMetric ):
109+ yield NDMetricAnnotation .from_common (annotation , label .data )
102110 else :
103111 raise TypeError (
104112 f"Unable to convert object to MAL format. `{ type (annotation .value )} `"
0 commit comments