Skip to content

Commit 426045d

Browse files
author
Matt Sokoloff
committed
clean up
1 parent 723d926 commit 426045d

File tree

30 files changed

+316
-315
lines changed

30 files changed

+316
-315
lines changed

labelbox/data/annotation_types/annotation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from typing import Any, Dict, List, Union
22

3-
from labelbox.data.annotation_types.classification.classification import (
4-
CheckList, Dropdown, Radio, Text)
5-
from labelbox.data.annotation_types.geometry import Geometry
6-
from labelbox.data.annotation_types.ner import TextEntity
7-
from labelbox.data.annotation_types.reference import FeatureSchemaRef
3+
from .classification import Checklist, Dropdown, Radio, Text
4+
from .feature import FeatureSchemaRef
5+
from .geometry import Geometry
6+
from .ner import TextEntity
87

98

109
class BaseAnnotation(FeatureSchemaRef):
@@ -17,7 +16,7 @@ class ObjectAnnotation(BaseAnnotation):
1716

1817

1918
class ClassificationAnnotation(BaseAnnotation):
20-
value: Union[Text, CheckList, Radio, Dropdown]
19+
value: Union[Text, Checklist, Radio, Dropdown]
2120

2221

2322
ClassificationAnnotation.update_forward_refs()
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from .classification import Dropdown, Text, CheckList, Radio, ClassificationAnswer
1+
from .classification import (Checklist, ClassificationAnswer, Dropdown, Radio,
2+
Text)

labelbox/data/annotation_types/classification/classification.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from typing import Any, Dict, List
22

3-
from labelbox.data.annotation_types.reference import FeatureSchemaRef
43
from pydantic.main import BaseModel
54

5+
from ..feature import FeatureSchemaRef
6+
67

78
class ClassificationAnswer(FeatureSchemaRef):
89
extra: Dict[str, Any] = {}
@@ -12,7 +13,7 @@ class Radio(BaseModel):
1213
answer: ClassificationAnswer
1314

1415

15-
class CheckList(BaseModel):
16+
class Checklist(BaseModel):
1617
answer: List[ClassificationAnswer]
1718

1819

labelbox/data/annotation_types/collection.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from typing import Callable, Generator, Iterable, Union
44
from uuid import uuid4
55

6-
from labelbox.data.annotation_types.label import Label
7-
from labelbox.data.generator import PrefetchGenerator
8-
from labelbox.orm.model import Entity
9-
from labelbox.schema.ontology import OntologyBuilder
106
from tqdm import tqdm
117

8+
from labelbox.schema.ontology import OntologyBuilder
9+
from labelbox.orm.model import Entity
10+
from ..generator import PrefetchGenerator
11+
from .label import Label
12+
1213
logger = logging.getLogger(__name__)
1314

1415

@@ -74,7 +75,7 @@ def add_to_dataset(self,
7475
# The workaround is creating a new dataset
7576
"""
7677
self._ensure_unique_external_ids()
77-
self.add_urls_to_data(signer, max_concurrency=max_concurrency)
78+
self.add_url_to_data(signer, max_concurrency=max_concurrency)
7879
upload_task = dataset.create_data_rows([{
7980
Entity.DataRow.row_data: label.data.url,
8081
Entity.DataRow.external_id: label.data.external_id
@@ -89,9 +90,7 @@ def add_to_dataset(self,
8990
label.data.uid = data_row_lookup[label.data.external_id]
9091
return self
9192

92-
def add_urls_to_masks(self,
93-
signer,
94-
max_concurrency=20) -> "LabelCollection":
93+
def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelCollection":
9594
"""
9695
Creates a data row id for each data row that needs it. If the data row exists then it skips the row.
9796
TODO: Add error handling..
@@ -102,7 +101,7 @@ def add_urls_to_masks(self,
102101
...
103102
return self
104103

105-
def add_urls_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
104+
def add_url_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
106105
"""
107106
TODO: Add error handling..
108107
"""
@@ -152,18 +151,18 @@ def _assign_ids(label: Label):
152151
self._fns['assign_schema_ids'] = _assign_ids
153152
return self
154153

155-
def add_urls_to_data(self, signer: Callable[[bytes],
156-
str]) -> "LabelGenerator":
154+
def add_url_to_data(self, signer: Callable[[bytes],
155+
str]) -> "LabelGenerator":
157156
"""
158157
Updates masks to have `url` attribute
159158
Doesn't update masks that already have urls
160159
"""
161160

162-
def _add_urls_to_data(label: Label):
161+
def _add_url_to_data(label: Label):
163162
label.add_url_to_data(signer)
164163
return label
165164

166-
self._fns['_add_urls_to_data'] = _add_urls_to_data
165+
self._fns['_add_url_to_data'] = _add_url_to_data
167166
return self
168167

169168
def add_to_dataset(self, dataset,
@@ -176,18 +175,18 @@ def _add_to_dataset(label: Label):
176175
self._fns['assign_datarow_ids'] = _add_to_dataset
177176
return self
178177

179-
def add_urls_to_masks(self, signer: Callable[[bytes],
180-
str]) -> "LabelGenerator":
178+
def add_url_to_masks(self, signer: Callable[[bytes],
179+
str]) -> "LabelGenerator":
181180
"""
182181
Updates masks to have `url` attribute
183182
Doesn't update masks that already have urls
184183
"""
185184

186-
def _add_urls_to_masks(label: Label):
185+
def _add_url_to_masks(label: Label):
187186
label.add_url_to_masks(signer)
188187
return label
189188

190-
self._fns['add_urls_to_masks'] = _add_urls_to_masks
189+
self._fns['add_url_to_masks'] = _add_url_to_masks
191190
return self
192191

193192
def __next__(self):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .raster import RasterData
2+
from .text import TextData
3+
from .video import VideoData

labelbox/data/annotation_types/data/raster.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
from typing import Callable, Optional
12
from io import BytesIO
2-
from typing import Any, Callable, Dict, Optional
33

44
import numpy as np
55
import requests
6-
from labelbox.data.annotation_types.reference import DataRowRef
6+
from pydantic import root_validator
77
from PIL import Image
8-
from pydantic import ValidationError, root_validator
98

9+
from .base_data import BaseData
1010

11-
class RasterData(DataRowRef):
11+
12+
class RasterData(BaseData):
1213
"""
1314
15+
1416
"""
1517
im_bytes: Optional[bytes] = None
1618
file_path: Optional[str] = None
@@ -49,7 +51,6 @@ def data(self) -> np.ndarray:
4951
raise ValueError("Must set either url, file_path or im_bytes")
5052

5153
def create_url(self, signer: Callable[[bytes], str]) -> None:
52-
5354
if self.url is not None:
5455
return self.url
5556
elif self.im_bytes is not None:

labelbox/data/annotation_types/data/text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Callable, Optional
22

33
import requests
4-
from labelbox.data.annotation_types.reference import DataRowRef
5-
from pydantic import ValidationError, root_validator
4+
from pydantic import root_validator
65

6+
from .base_data import BaseData
77

8-
class TextData(DataRowRef):
8+
9+
class TextData(BaseData):
910
file_path: Optional[str] = None
1011
text: Optional[str] = None
1112
url: Optional[str] = None

labelbox/data/annotation_types/data/video.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import logging
22
import os
33
import urllib.request
4-
from typing import Any, Callable, Dict, Generator, Optional, Tuple
4+
from typing import Callable, Dict, Generator, Optional, Tuple
55
from uuid import uuid4
66

77
import cv2
88
import numpy as np
9-
from labelbox.data.annotation_types.reference import DataRowRef
10-
from pydantic import ValidationError, root_validator
9+
from pydantic import root_validator
10+
11+
from .base_data import BaseData
1112

1213
logger = logging.getLogger(__name__)
1314

1415

15-
class VideoData(DataRowRef):
16+
class VideoData(BaseData):
1617
file_path: Optional[str] = None
1718
url: Optional[str] = None
1819
frames: Optional[Dict[int, np.ndarray]] = None

labelbox/data/annotation_types/geometry/line.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List, Optional, Dict, Any
1+
from typing import List
22

33
import geojson
44
import numpy as np
55
import cv2
66

7-
from labelbox.data.annotation_types.geometry.point import Point
8-
from labelbox.data.annotation_types.geometry.geometry import Geometry
7+
from .point import Point
8+
from .geometry import Geometry
99

1010

1111
class Line(Geometry):

labelbox/data/annotation_types/geometry/mask.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Any, Dict, Tuple
22

33
import numpy as np
4-
from labelbox.data.annotation_types.data.raster import RasterData
5-
from labelbox.data.annotation_types.geometry.geometry import Geometry
64
from rasterio.features import shapes
75
from shapely.geometry import MultiPolygon, shape
86

7+
from ..data.raster import RasterData
8+
from .geometry import Geometry
9+
910

1011
class Mask(Geometry):
1112
# Raster data can be shared across multiple masks... or not

0 commit comments

Comments
 (0)