File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 11from enum import Enum
22from typing import List , Optional , Tuple
33
4- from pydantic import BaseModel , validator
4+ from pydantic import BaseModel , validator , root_validator
55from labelbox .data .annotation_types .annotation import ClassificationAnnotation , ObjectAnnotation
66
77from labelbox .data .annotation_types .annotation import ClassificationAnnotation , ObjectAnnotation
@@ -81,14 +81,24 @@ class DICOMObjectAnnotation(VideoObjectAnnotation):
8181 keyframe (bool): Whether or not this annotation was a human generated or interpolated annotation
8282 segment_id (Optional[Int]): Index of video segment this annotation belongs to
8383 classifications (List[ClassificationAnnotation]) = []
84- extra (Dict[str, Any])
84+ extra (Dict[str, Any])
8585 """
8686 group_key : GroupKey
8787
8888
8989class MaskFrame (_CamelCaseMixin , BaseModel ):
9090 index : int
91- instance_uri : str
91+ instance_uri : Optional [str ] = None
92+ im_bytes : Optional [bytes ] = None
93+
94+ @root_validator ()
95+ def validate_args (cls , values ):
96+ im_bytes = values .get ("im_bytes" )
97+ instance_uri = values .get ("instance_uri" )
98+
99+ if im_bytes == instance_uri == None :
100+ raise ValueError ("One of `instance_uri`, `im_bytes` required." )
101+ return values
92102
93103 @validator ("instance_uri" )
94104 def validate_uri (cls , v ):
Original file line number Diff line number Diff line change @@ -501,13 +501,23 @@ class NDVideoMasks(NDJsonBase, ConfidenceMixin):
501501 masks : NDVideoMasksFramesInstances
502502
503503 def to_common (self ) -> VideoMaskAnnotation :
504+ for mask_frame in self .masks .frames :
505+ if mask_frame .im_bytes :
506+ mask_frame .im_bytes = base64 .b64decode (
507+ mask_frame .im_bytes .encode ('utf-8' ))
508+
504509 return VideoMaskAnnotation (
505510 frames = self .masks .frames ,
506511 instances = self .masks .instances ,
507512 )
508513
509514 @classmethod
510515 def from_common (cls , annotation , data ):
516+ for mask_frame in annotation .frames :
517+ if mask_frame .im_bytes :
518+ mask_frame .im_bytes = base64 .b64encode (
519+ mask_frame .im_bytes ).decode ('utf-8' )
520+
511521 return cls (
512522 data_row = DataRow (id = data .uid , global_key = data .global_key ),
513523 masks = NDVideoMasksFramesInstances (frames = annotation .frames ,
You can’t perform that action at this time.
0 commit comments