Skip to content

Commit dd67d5b

Browse files
author
Matt Sokoloff
committed
ndjson conversion passing tests
1 parent 4f3fc35 commit dd67d5b

File tree

21 files changed

+734
-36
lines changed

21 files changed

+734
-36
lines changed

labelbox/data/annotation_types/annotation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from labelbox.data.annotation_types.classification.classification import Dropdown, Text, CheckList, Radio
21
from typing import List, Union, Dict, Any
32

3+
from labelbox.data.annotation_types.classification.classification import Dropdown, Text, CheckList, Radio
44
from labelbox.data.annotation_types.reference import FeatureSchemaRef
55
from labelbox.data.annotation_types.ner import TextEntity
66
from labelbox.data.annotation_types.geometry import Geometry
@@ -16,7 +16,7 @@ class ObjectAnnotation(BaseAnnotation):
1616

1717

1818
class ClassificationAnnotation(BaseAnnotation):
19-
value: Union[Dropdown, Text, CheckList, Radio]
19+
value: Union[Text, CheckList, Radio, Dropdown]
2020

2121

2222
ClassificationAnnotation.update_forward_refs()

labelbox/data/annotation_types/collection.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
from labelbox.orm.model import Entity
2-
from labelbox.data.annotation_types.classification.classification import Text, Radio, CheckList, Dropdown
3-
from typing import Dict, Generator, Iterable, List, Any, Union
4-
from pydantic import BaseModel
51
from concurrent.futures import ThreadPoolExecutor, as_completed
2+
from typing import Iterable, List, Any
63
from uuid import uuid4
74

5+
from pydantic import BaseModel
6+
87
from labelbox.data.annotation_types.label import Label
9-
from labelbox.schema.ontology import OntologyBuilder, Tool, Classification
10-
from labelbox.data.annotation_types.geometry import Rectangle, Polygon, Point, Mask, Line
11-
from labelbox.data.annotation_types.data.raster import RasterData
8+
from labelbox.orm.model import Entity
129

1310

1411
class LabelCollection(BaseModel):

labelbox/data/annotation_types/data/raster.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ def validate_args(cls, values):
7070
im_bytes = values.get("im_bytes")
7171
url = values.get("url")
7272
arr = values.get("arr")
73-
if file_path == im_bytes == url == None and arr is None:
73+
uid = values.get('uid')
74+
if uid == file_path == im_bytes == url == None and arr is None:
7475
raise ValidationError(
75-
"One of `file_path`, `im_bytes`, `url`, or `arr` required.")
76+
"One of `file_path`, `im_bytes`, `url`, `uid` or `arr` required.")
7677
if arr is not None:
7778
if arr.dtype != np.uint8:
7879
raise ValidationError(

labelbox/data/annotation_types/data/text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ def create_url(self, signer: Callable[[bytes], str]) -> None:
4545
@root_validator
4646
def validate_date(cls, values):
4747
file_path = values.get("file_path")
48-
im_bytes = values.get("text")
48+
text = values.get("text")
4949
url = values.get("url")
50-
if file_path == im_bytes == url == None:
50+
uid = values.get('uid')
51+
if uid == file_path == text == url == None:
5152
raise ValidationError(
52-
"One of `file_path`, `im_bytes`, or `url` required.")
53+
"One of `file_path`, `text`, `uid`, or `url` required.")
5354
return values
5455

5556
class config:

labelbox/data/annotation_types/data/video.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ def frames_to_video(self,
9999
@root_validator
100100
def validate_data(cls, values):
101101
file_path = values.get("file_path")
102-
im_bytes = values.get("url")
103-
url = values.get("frames")
104-
if file_path == im_bytes == url == None:
102+
url = values.get("url")
103+
frames = values.get("frames")
104+
uid = values.get("uid")
105+
106+
if uid == file_path == frames == url == None:
105107
raise ValidationError(
106-
"One of `file_path`, `frames`, or `url` required.")
108+
"One of `file_path`, `frames`, `uid`, or `url` required.")
107109
return values
108110

109111
class Config:

labelbox/data/annotation_types/geometry/rectangle.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ def raster(self, height: int, width: int, color: int = 255) -> np.ndarray:
2727
canvas = np.zeros((height, width), dtype=np.uint8)
2828
pts = np.array(self.geometry['coordinates']).astype(np.int32)
2929
return cv2.fillPoly(canvas, pts=pts, color=color)
30+
31+
# TODO: Validate the start points are less than the end points

labelbox/data/annotation_types/label.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
from labelbox.data.annotation_types.ner import TextEntity
2-
from labelbox.data.annotation_types.geometry import Geometry
3-
from labelbox.data.annotation_types.classification.classification import ClassificationAnswer, Radio, Text
4-
from labelbox.data.annotation_types.geometry.mask import Mask
5-
from typing import Type, Union, List, Dict, Any
1+
from typing import Union, List, Dict, Any
2+
3+
from pydantic import BaseModel
64

75
from labelbox.schema.ontology import Classification as OClassification, Option
6+
from labelbox.data.annotation_types.classification.classification import ClassificationAnswer
87
from labelbox.data.annotation_types.annotation import AnnotationType, ClassificationAnnotation, ObjectAnnotation, VideoAnnotationType
98
from labelbox.data.annotation_types.data.raster import RasterData
109
from labelbox.data.annotation_types.data.text import TextData
1110
from labelbox.data.annotation_types.data.video import VideoData
1211
from labelbox.data.annotation_types.metrics import Metric
13-
from pydantic import BaseModel
12+
from labelbox.data.annotation_types.geometry.mask import Mask
1413

1514

1615
class Label(BaseModel):
17-
# TODO: This sounds too much like the other label we need to rename this...
1816
data: Union[VideoData, RasterData, TextData]
1917
annotations: List[Union[AnnotationType, VideoAnnotationType, Metric]] = []
2018
extra: Dict[str, Any] = {}

labelbox/data/annotation_types/metrics.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import uuid
2-
31
from pydantic import BaseModel
42

53

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Optional
2-
from pydantic import BaseModel, root_validator, ValidationError
2+
from pydantic import BaseModel
33

44

55
class DataRowRef(BaseModel):
@@ -8,5 +8,9 @@ class DataRowRef(BaseModel):
88

99

1010
class FeatureSchemaRef(BaseModel):
11-
display_name: str
11+
display_name: Optional[str] = None
1212
schema_id: Optional[str] = None
13+
14+
# TODO: Validate that one of these is set..
15+
16+

labelbox/data/serialization/labelbox_v1/classifications.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
from labelbox.data.annotation_types.classification.classification import Dropdown
2-
from labelbox.data.annotation_types.annotation import AnnotationType, ClassificationAnnotation
31
from typing import List, Union
4-
from pydantic.main import BaseModel
52

6-
from pydantic.schema import schema
7-
from pydantic.typing import display_as_type
3+
from pydantic.main import BaseModel
4+
from labelbox.data.annotation_types.classification.classification import Dropdown
5+
from labelbox.data.annotation_types.annotation import AnnotationType, ClassificationAnnotation
86

97
from labelbox.data.serialization.labelbox_v1.feature import LBV1Feature
108
from labelbox.data.annotation_types.classification import Text, Radio, CheckList, ClassificationAnswer
@@ -13,7 +11,6 @@
1311
class LBV1ClassificationAnswer(LBV1Feature):
1412
...
1513

16-
1714
class LBV1Radio(LBV1Feature):
1815
answer: LBV1ClassificationAnswer
1916

0 commit comments

Comments
 (0)