Skip to content

Commit 45961d2

Browse files
committed
update to converter types
1 parent 721af34 commit 45961d2

File tree

7 files changed

+291
-28
lines changed

7 files changed

+291
-28
lines changed

labelbox/data/serialization/labelbox_v1/converter.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def label_generator():
5454
)
5555

5656
if example['Label']:
57-
# Don't construct empty dict
5857
yield LBV1Label(**example).to_common()
5958

6059
return LabelGenerator(data=label_generator())

labelbox/data/serialization/labelbox_v1/label.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from labelbox.data.annotation_types.data.tiled_image import TiledImageData
12
from labelbox.utils import camel_case
23
from typing import List, Optional, Union
34

@@ -17,8 +18,10 @@ class LBV1LabelAnnotations(LBV1Classifications, LBV1Objects):
1718

1819
def to_common(
1920
self) -> List[Union[ObjectAnnotation, ClassificationAnnotation]]:
21+
# print("\nHELLO WORLD BEFORE TO COMMON\n")
2022
classifications = LBV1Classifications.to_common(self)
2123
objects = LBV1Objects.to_common(self)
24+
# print(f"here...\n{len(objects)} \n")
2225
return [*objects, *classifications]
2326

2427
@classmethod
@@ -171,8 +174,9 @@ def from_common(cls, label: Label):
171174
external_id=label.data.external_id,
172175
**label.extra)
173176

174-
def _data_row_to_common(self) -> Union[ImageData, TextData, VideoData]:
175-
# Use data row information to construct the appropriate annotatin type
177+
def _data_row_to_common(
178+
self) -> Union[ImageData, TextData, VideoData, TiledImageData]:
179+
# Use data row information to construct the appropriate annotation type
176180
data_row_info = {
177181
'url' if self._is_url() else 'text': self.row_data,
178182
'external_id': self.external_id,
@@ -228,7 +232,8 @@ def _row_contains(self, substrs):
228232
return any([substr in self.row_data for substr in substrs])
229233

230234
def _is_url(self):
231-
return self.row_data.startswith(("http://", "https://"))
235+
return self.row_data.startswith(
236+
("http://", "https://")) or "tileLayerUrl" in self.row_data
232237

233238
class Config:
234239
allow_population_by_field_name = True

labelbox/data/serialization/labelbox_v1/objects.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import Any, Dict, List, Optional, Union, Type
2+
try:
3+
from typing import Literal
4+
except:
5+
from typing_extensions import Literal
26

3-
from pydantic import BaseModel, validator
7+
from pydantic import BaseModel, validator, Field
48

59
from .classification import LBV1Checklist, LBV1Classifications, LBV1Radio, LBV1Text, LBV1Dropdown
610
from .feature import LBV1Feature
@@ -42,47 +46,50 @@ def validate_subclasses(cls, value, field):
4246
return value
4347

4448

45-
class _TIPoint(BaseModel):
46-
coordinates: List[float]
49+
class _Coordinates(BaseModel):
50+
"""Union of the possible coordinate lists in tiled imagery exports"""
51+
coordinates: Union[List[float], List[List[float]], List[List[List[float]]]]
4752

4853

49-
class LBV1TIPoint(BaseModel):
50-
point: _TIPoint
54+
class LBV1TIPoint(LBV1ObjectBase):
55+
object_type: Literal['point'] = Field(..., alias='type')
56+
geometry: _Coordinates
5157

5258
def to_common(self) -> Point:
53-
lng, lat = self.point.coordinates
59+
lng, lat = self.geometry.coordinates
5460
return Point(x=lng, y=lat)
5561

5662

57-
class LBV1TILine(BaseModel):
58-
line: List[_TIPoint]
63+
class LBV1TILine(LBV1ObjectBase):
64+
object_type: Literal['polyline'] = Field(..., alias='type')
65+
geometry: _Coordinates
5966

6067
def to_common(self) -> Line:
6168
return Line(points=[
62-
LBV1TIPoint(point=point).to_common() for point in self.line
69+
Point(x=coord[0], y=coord[1]) for coord in self.geometry.coordinates
6370
])
6471

6572

66-
class LBV1TIPolygon(BaseModel):
67-
polygon: List[List[_TIPoint]]
73+
class LBV1TIPolygon(LBV1ObjectBase):
74+
object_type: Literal['polygon'] = Field(..., alias='type')
75+
geometry: _Coordinates
6876

6977
def to_common(self) -> Polygon:
70-
for inner_list in self.polygon:
71-
return Polygon(points=[
72-
LBV1TIPoint(point=point).to_common() for point in inner_list
73-
])
78+
for coord_list in self.geometry.coordinates:
79+
return Polygon(
80+
points=[Point(x=coord[0], y=coord[1]) for coord in coord_list])
7481

7582

76-
class LBV1TIRectangle(BaseModel):
77-
bbox: List[List[_TIPoint]]
83+
class LBV1TIRectangle(LBV1ObjectBase):
84+
object_type: Literal['rectangle'] = Field(..., alias='type')
85+
geometry: _Coordinates
7886

7987
def to_common(self) -> Rectangle:
80-
inner_list = self.bbox[0]
81-
start = inner_list[0]
82-
end = inner_list[2]
83-
for inner_list in self.bbox:
84-
return Rectangle(start=LBV1TIPoint(point=start).to_common(),
85-
end=LBV1TIPoint(point=end).to_common())
88+
coord_list = self.geometry.coordinates[0]
89+
start = coord_list[0]
90+
end = coord_list[2]
91+
return Rectangle(start=Point(x=start[0], y=start[1]),
92+
end=Point(x=end[0], y=end[1]))
8693

8794

8895
class _Point(BaseModel):

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ typeguard
1414
imagesize
1515
pyproj
1616
pygeotile
17+
typing-extensions

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
extras_require={
3030
'data': [
3131
"shapely", "geojson", "numpy", "rasterio", "PILLOW",
32-
"opencv-python", "typeguard", "imagesize", "pyproj", "pygeotile"
32+
"opencv-python", "typeguard", "imagesize", "pyproj", "pygeotile",
33+
"typing-extensions"
3334
],
3435
},
3536
classifiers=[
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
[{
2+
"ID": "ckwdp4o2t8fjq108j6c8t9507",
3+
"DataRow ID": "ckwdowhd91rp80zqh2ev9cx9w",
4+
"Labeled Data": "{\n \"tileLayerUrl\": \"https://s3-us-east-2.amazonaws.com/lb-ron/CACI/ron_mctiles/{z}/{x}/{y}.png\",\n \"bounds\": [\n [19.3469381, -99.3922238],\n [19.42443609, -99.22896466]\n ],\n \"minZoom\": 12,\n \"maxZoom\": 21,\n \"tileSize\": 10000,\n \"epsg\": \"EPSG4326\",\n \"alternativeLayers\": [{\n \"tileLayerUrl\": \"https://api.mapbox.com/styles/v1/mapbox/satellite-streets-v11/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw\",\n \"name\": \"Satellite\"\n },\n {\n \"tileLayerUrl\": \"https://api.mapbox.com/styles/v1/mapbox/navigation-guidance-night-v4/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw\",\n \"name\": \"Guidance\"\n }\n ]\n}",
5+
"Label": {
6+
"objects": [{
7+
"featureId": "ckwdp4zzf00003g6bmj3fnk07",
8+
"schemaId": "ckw3oiu476k780zbpdxqbawbg",
9+
"color": "#ff0000",
10+
"title": "polygon",
11+
"value": "polygon",
12+
"type": "polygon",
13+
"geometry": {
14+
"coordinates": [
15+
[
16+
[-99.2032814025879, 19.410744883371013],
17+
[-99.18886184692384, 19.41123059525866],
18+
[-99.19281005859376, 19.40264947166554],
19+
[-99.2087745666504, 19.397953948267737],
20+
[-99.21255111694336, 19.398439698351616],
21+
[-99.2032814025879, 19.410744883371013]
22+
]
23+
]
24+
}
25+
}, {
26+
"featureId": "ckwdp52w900023g6bkq3p5c9a",
27+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
28+
"color": "#FF34FF",
29+
"title": "point",
30+
"value": "point",
31+
"type": "point",
32+
"geometry": {
33+
"coordinates": [-99.16156768798828, 19.405725775580528]
34+
}
35+
}, {
36+
"featureId": "ckwdp53mx00043g6bxvgz1odn",
37+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
38+
"color": "#FF34FF",
39+
"title": "point",
40+
"value": "point",
41+
"type": "point",
42+
"geometry": {
43+
"coordinates": [-99.19692993164064, 19.378036946667645]
44+
}
45+
}, {
46+
"featureId": "ckwdp547j00063g6bn19303pv",
47+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
48+
"color": "#FF34FF",
49+
"title": "point",
50+
"value": "point",
51+
"type": "point",
52+
"geometry": {
53+
"coordinates": [-99.16019439697268, 19.37447429931405]
54+
}
55+
}, {
56+
"featureId": "ckwdp54yt00073g6bgawsm0dk",
57+
"schemaId": "ckwdnchwp843o108j6eof4qdi",
58+
"color": "#FF4A46",
59+
"title": "poly line",
60+
"value": "poly_line",
61+
"type": "polyline",
62+
"geometry": {
63+
"coordinates": [
64+
[-99.2161560058594, 19.358765334468117],
65+
[-99.19795989990236, 19.36216637277295],
66+
[-99.18560028076172, 19.356497936190603],
67+
[-99.17324066162112, 19.360222930999285]
68+
]
69+
}
70+
}, {
71+
"featureId": "ckx841y2700013g69pboavi3s",
72+
"schemaId": "ckwdnchwp843s108j5w9i491y",
73+
"color": "#006FA6",
74+
"title": "bbox",
75+
"value": "bbox",
76+
"type": "rectangle",
77+
"geometry": {
78+
"coordinates": [
79+
[
80+
[-99.36567524971268, 19.34717117508651],
81+
[-99.36567524971268, 19.41999425190506],
82+
[-99.3649886680726, 19.41999425190506],
83+
[-99.3649886680726, 19.34717117508651],
84+
[-99.36567524971268, 19.34717117508651]
85+
]
86+
]
87+
}
88+
}],
89+
"classifications": [],
90+
"relationships": []
91+
},
92+
"Created By": "jtso@labelbox.com",
93+
"Project Name": "tms_mal_project",
94+
"Created At": "2021-11-24T15:43:41.000Z",
95+
"Updated At": "2021-12-15T22:34:02.363Z",
96+
"Seconds to Label": 910.657,
97+
"External ID": null,
98+
"Agreement": -1,
99+
"Benchmark Agreement": -1,
100+
"Benchmark ID": null,
101+
"Dataset Name": "mx_large_tiled.json",
102+
"Reviews": [],
103+
"View Label": "https://editor.labelbox.com?project=ckw3oipbx9iee0zc321ut9aua&label=ckwdp4o2t8fjq108j6c8t9507",
104+
"Has Open Issues": 0,
105+
"Skipped": false
106+
},
107+
{
108+
"ID": "ckwmlfgyobl6r0z9p0jhb3235",
109+
"DataRow ID": "ckwb4r0fk005c0zqo5le521ih",
110+
"Labeled Data": "\n {\n \"tileLayerUrl\": \"https://labelbox.s3-us-west-2.amazonaws.com/pathology/{z}/{x}/{y}.png\",\n \"minZoom\": 1,\n \"maxZoom\": 8.5,\n \"bounds\": [\n [0, 0],\n [135, 128]\n ],\n \"epsg\": \"Simple\",\n \"version\": 2,\n \"tileSize\": 128\n }",
111+
"Label": {
112+
"objects": [{
113+
"featureId": "ckx83js8l00033g691hz1zs4g",
114+
"schemaId": "ckw3oiu476k780zbpdxqbawbg",
115+
"color": "#ff0000",
116+
"title": "polygon",
117+
"value": "polygon",
118+
"polygon": [{
119+
"x": 52.49074938173845,
120+
"y": 24.209072254552296
121+
}, {
122+
"x": 45.99135397338951,
123+
"y": 33.20339437483625
124+
}, {
125+
"x": 52.99070287468838,
126+
"y": 38.94976684057322
127+
}, {
128+
"x": 58.24021455066253,
129+
"y": 30.455129282527267
130+
}]
131+
}, {
132+
"featureId": "ckwmlfm5r00023g6bvigbvtyh",
133+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
134+
"color": "#FF34FF",
135+
"title": "point",
136+
"value": "point",
137+
"point": {
138+
"x": 0,
139+
"y": 128
140+
}
141+
}, {
142+
"featureId": "ckwmlg1oi00053g6b9peptx9l",
143+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
144+
"color": "#FF34FF",
145+
"title": "point",
146+
"value": "point",
147+
"point": {
148+
"x": 22.352061642639708,
149+
"y": 128
150+
}
151+
}, {
152+
"featureId": "ckwnmjc6600013g6brrg60h3k",
153+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
154+
"color": "#FF34FF",
155+
"title": "point",
156+
"value": "point",
157+
"point": {
158+
"x": 5.921614630706372,
159+
"y": 6.468767056927199
160+
}
161+
}, {
162+
"featureId": "ckwnmjeul00033g6b2b7rezcz",
163+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
164+
"color": "#FF34FF",
165+
"title": "point",
166+
"value": "point",
167+
"point": {
168+
"x": 132.24738299361238,
169+
"y": 64.15800846258857
170+
}
171+
}, {
172+
"featureId": "ckwnmjfu800053g6b5tea82ip",
173+
"schemaId": "ckwdnchwp843m108j4o6f7zvg",
174+
"color": "#FF34FF",
175+
"title": "point",
176+
"value": "point",
177+
"point": {
178+
"x": 135,
179+
"y": 89.80450287438632
180+
}
181+
}, {
182+
"featureId": "ckx83jvyd00063g69wndhctep",
183+
"schemaId": "ckwdnchwp843o108j6eof4qdi",
184+
"color": "#FF4A46",
185+
"title": "poly line",
186+
"value": "poly_line",
187+
"line": [{
188+
"x": 23.743423537118105,
189+
"y": 49.692984928690166
190+
}, {
191+
"x": 36.742214353816,
192+
"y": 49.19330036645216
193+
}, {
194+
"x": 42.49167952274007,
195+
"y": 58.18762248673612
196+
}]
197+
}, {
198+
"featureId": "ckx83jplk00013g69d2mjchbg",
199+
"schemaId": "ckwdnchwp843s108j5w9i491y",
200+
"color": "#006FA6",
201+
"title": "bbox",
202+
"value": "bbox",
203+
"bbox": {
204+
"top": 31.454498407003257,
205+
"left": 31.24272593136689,
206+
"height": 6.995583871331959,
207+
"width": 8.499209380148628
208+
}
209+
}],
210+
"classifications": [],
211+
"relationships": []
212+
},
213+
"Created By": "jtso@labelbox.com",
214+
"Project Name": "tms_mal_project",
215+
"Created At": "2021-11-30T21:17:42.000Z",
216+
"Updated At": "2021-12-15T22:19:57.398Z",
217+
"Seconds to Label": 421.39300000000003,
218+
"External ID": null,
219+
"Agreement": -1,
220+
"Benchmark Agreement": -1,
221+
"Benchmark ID": null,
222+
"Dataset Name": "simple tms",
223+
"Reviews": [],
224+
"View Label": "https://editor.labelbox.com?project=ckw3oipbx9iee0zc321ut9aua&label=ckwmlfgyobl6r0z9p0jhb3235",
225+
"Has Open Issues": 0,
226+
"Skipped": false
227+
}
228+
]

0 commit comments

Comments
 (0)