4141 Z_KEY ,
4242)
4343
44+ # TODO: refactor to reduce this file to under 1000 lines.
45+ # pylint: disable=C0302
46+
4447
4548class Annotation :
4649 """Internal base class, not to be used directly.
@@ -893,6 +896,53 @@ def to_payload(self) -> dict:
893896 return payload
894897
895898
899+ @dataclass
900+ class SceneCategoryAnnotation (Annotation ):
901+ """A scene category annotation.
902+
903+ ::
904+
905+ from nucleus import CategoryAnnotation
906+
907+ category = SceneCategoryAnnotation(
908+ label="running",
909+ reference_id="scene_1",
910+ taxonomy_name="action",
911+ )
912+
913+ Parameters:
914+ label (str): The label for this annotation.
915+ reference_id (str): User-defined ID of the scene to which to apply this annotation.
916+ taxonomy_name (Optional[str]): The name of the taxonomy this annotation conforms to.
917+ See :meth:`Dataset.add_taxonomy`.
918+ """
919+
920+ label : str
921+ reference_id : str
922+ taxonomy_name : Optional [str ] = None
923+ # todo(546247): add metadata support when required
924+ metadata : Optional [Dict ] = field (default_factory = dict )
925+
926+ @classmethod
927+ def from_json (cls , payload : dict ):
928+ return cls (
929+ label = payload [LABEL_KEY ],
930+ reference_id = payload [REFERENCE_ID_KEY ],
931+ taxonomy_name = payload .get (TAXONOMY_NAME_KEY , None ),
932+ )
933+
934+ def to_payload (self ) -> dict :
935+ payload = {
936+ LABEL_KEY : self .label ,
937+ TYPE_KEY : CATEGORY_TYPE ,
938+ GEOMETRY_KEY : {},
939+ REFERENCE_ID_KEY : self .reference_id ,
940+ }
941+ if self .taxonomy_name is not None :
942+ payload [TAXONOMY_NAME_KEY ] = self .taxonomy_name
943+ return payload
944+
945+
896946@dataclass
897947class AnnotationList :
898948 """Wrapper class separating a list of annotations by type."""
@@ -910,6 +960,9 @@ class AnnotationList:
910960 multi_category_annotations : List [MultiCategoryAnnotation ] = field (
911961 default_factory = list
912962 )
963+ scene_category_annotations : List [SceneCategoryAnnotation ] = field (
964+ default_factory = list
965+ )
913966 segmentation_annotations : List [SegmentationAnnotation ] = field (
914967 default_factory = list
915968 )
@@ -934,6 +987,8 @@ def add_annotations(self, annotations: List[Annotation]):
934987 self .category_annotations .append (annotation )
935988 elif isinstance (annotation , MultiCategoryAnnotation ):
936989 self .multi_category_annotations .append (annotation )
990+ elif isinstance (annotation , SceneCategoryAnnotation ):
991+ self .scene_category_annotations .append (annotation )
937992 else :
938993 assert isinstance (
939994 annotation , SegmentationAnnotation
@@ -952,6 +1007,7 @@ def __len__(self):
9521007 + len (self .cuboid_annotations )
9531008 + len (self .category_annotations )
9541009 + len (self .multi_category_annotations )
1010+ + len (self .scene_category_annotations )
9551011 + len (self .segmentation_annotations )
9561012 )
9571013
0 commit comments