Skip to content

Commit 60ab2a0

Browse files
committed
from_common to go to importable ndjson format
1 parent 6761544 commit 60ab2a0

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

labelbox/data/serialization/ndjson/objects.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class NDBaseObject(NDAnnotation):
2323
classifications: List[NDSubclassificationType] = []
2424

2525

26+
class VideoSupported(BaseModel):
27+
#support for video for objects are per-frame basis
28+
frame: int
29+
30+
2631
class _Point(BaseModel):
2732
x: float
2833
y: float
@@ -121,12 +126,9 @@ def from_common(cls, rectangle: Rectangle,
121126
classifications=classifications)
122127

123128

124-
class NDFrameRectangle(BaseModel):
125-
frame: int
129+
class NDFrameRectangle(VideoSupported):
126130
bbox: Bbox
127131

128-
#make a new class that has Frame as the base and then inherit from it
129-
130132
@classmethod
131133
def from_common(cls, frame: int, rectangle: Rectangle):
132134
return cls(frame=frame,
@@ -140,23 +142,19 @@ class NDSegment(BaseModel):
140142
keyframes: List[NDFrameRectangle]
141143

142144
@staticmethod
143-
#lets make NDFrameObject as a method to call on similar to the other one
145+
def lookup_segment_object_type(segment: List) -> "NDFrameObjectType":
146+
result = {Rectangle: NDFrameRectangle}.get(type(segment[0].value))
147+
return result
144148

145149
@classmethod
146150
def from_common(cls, segment):
147-
NDFrameObject = {
148-
Rectangle: NDFrameRectangle
149-
}.get(type(segment[0].value))
150-
151-
# for a in segment:
152-
# print("\nHELLO", a)
153-
b = cls(keyframes=[
154-
NDFrameObject.from_common(object_annotation.frame,
155-
object_annotation.value)
151+
nd_frame_object_type = cls.lookup_segment_object_type(segment)
152+
153+
return cls(keyframes=[
154+
nd_frame_object_type.from_common(object_annotation.frame,
155+
object_annotation.value)
156156
for object_annotation in segment
157157
])
158-
# print("\n\n B AS DICT IS", b.dict(by_alias=True))
159-
return b
160158

161159

162160
class NDSegments(NDBaseObject):
@@ -331,3 +329,5 @@ def lookup_object(annotation: ObjectAnnotation) -> "NDObjectType":
331329

332330
NDObjectType = Union[NDLine, NDPolygon, NDPoint, NDRectangle, NDMask,
333331
NDTextEntity]
332+
333+
NDFrameObjectType = NDFrameRectangle

0 commit comments

Comments
 (0)