Skip to content

Commit ef5c450

Browse files
committed
initial pass at creation of conversion from export to a labelbox format
1 parent d44e091 commit ef5c450

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

labelbox/data/serialization/labelbox_v1/objects.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -259,33 +259,40 @@ def from_common(cls, text_entity: TextEntity,
259259
**extra)
260260

261261

262+
class LBV1DocumentRectangle(LBV1Rectangle):
263+
unit: str
264+
page: int
265+
266+
262267
class LBV1Objects(BaseModel):
263-
objects: List[Union[LBV1Line, LBV1Point, LBV1Polygon, LBV1Rectangle,
264-
LBV1TextEntity, LBV1Mask, LBV1TIPoint, LBV1TILine,
265-
LBV1TIPolygon, LBV1TIRectangle]]
268+
objects: List[Union[LBV1DocumentRectangle, LBV1Line, LBV1Point, LBV1Polygon,
269+
LBV1Rectangle, LBV1TextEntity, LBV1Mask, LBV1TIPoint,
270+
LBV1TILine, LBV1TIPolygon, LBV1TIRectangle,]]
266271

267272
def to_common(self) -> List[ObjectAnnotation]:
268273
objects = [
269-
ObjectAnnotation(value=obj.to_common(),
270-
classifications=[
271-
ClassificationAnnotation(
272-
value=cls.to_common(),
273-
feature_schema_id=cls.schema_id,
274-
name=cls.title,
275-
extra={
276-
'feature_id': cls.feature_id,
277-
'title': cls.title,
278-
'value': cls.value
279-
}) for cls in obj.classifications
280-
],
281-
name=obj.title,
282-
feature_schema_id=obj.schema_id,
283-
extra={
284-
'instanceURI': obj.instanceURI,
285-
'color': obj.color,
286-
'feature_id': obj.feature_id,
287-
'value': obj.value,
288-
}) for obj in self.objects
274+
ObjectAnnotation(
275+
value=obj.to_common(),
276+
classifications=[
277+
ClassificationAnnotation(value=cls.to_common(),
278+
feature_schema_id=cls.schema_id,
279+
name=cls.title,
280+
extra={
281+
'feature_id': cls.feature_id,
282+
'title': cls.title,
283+
'value': cls.value
284+
}) for cls in obj.classifications
285+
],
286+
name=obj.title,
287+
feature_schema_id=obj.schema_id,
288+
extra={
289+
'instanceURI': obj.instanceURI,
290+
'color': obj.color,
291+
'feature_id': obj.feature_id,
292+
'value': obj.value,
293+
'page': obj.page if hasattr(obj, 'page') else None,
294+
'unit': obj.unit if hasattr(obj, 'unit') else None,
295+
}) for obj in self.objects
289296
]
290297
return objects
291298

0 commit comments

Comments
 (0)