Skip to content

Commit c359958

Browse files
author
Matt Sokoloff
committed
merge
2 parents 5ad97a1 + c9e5877 commit c359958

File tree

8 files changed

+33
-38
lines changed

8 files changed

+33
-38
lines changed

labelbox/data/annotation_types/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424

2525
from .label import Label
2626

27-
from .collection import LabelCollection
27+
from .collection import LabelList
2828
from .collection import LabelGenerator

labelbox/data/annotation_types/annotation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BaseAnnotation(FeatureSchema):
1515

1616

1717
class ClassificationAnnotation(BaseAnnotation):
18-
"""Class represneting classification annotations (annotations that don't have a location) """
18+
"""Class representing classification annotations (annotations that don't have a location) """
1919
value: Union[Text, Checklist, Radio, Dropdown]
2020

2121

labelbox/data/annotation_types/collection.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
logger = logging.getLogger(__name__)
1414

1515

16-
class LabelCollection:
16+
class LabelList:
1717
"""
1818
A container for interacting with a collection of labels.
1919
Less memory efficient than LabelGenerator but more performant and convenient to use.
@@ -25,16 +25,15 @@ def __init__(self, data: Iterable[Label]):
2525
self._index = 0
2626

2727
def assign_schema_ids(
28-
self,
29-
ontology_builder: "ontology.OntologyBuilder") -> "LabelCollection":
28+
self, ontology_builder: "ontology.OntologyBuilder") -> "LabelList":
3029
"""
3130
Adds schema ids to all FeatureSchema objects in the Labels.
3231
This is necessary for MAL.
3332
3433
Args:
35-
ontology_builder: The ontology that matches the feature names assigned to objects in this LabelCollection
34+
ontology_builder: The ontology that matches the feature names assigned to objects in this LabelList
3635
Returns:
37-
LabelCollection. useful for chaining these modifying functions
36+
LabelList. useful for chaining these modifying functions
3837
"""
3938
for label in self._data:
4039
label.assign_schema_ids(ontology_builder)
@@ -43,7 +42,7 @@ def assign_schema_ids(
4342
def add_to_dataset(self,
4443
dataset: "Entity.Dataset",
4544
signer: Callable[[bytes], str],
46-
max_concurrency=20) -> "LabelCollection":
45+
max_concurrency=20) -> "LabelList":
4746
"""
4847
Creates data rows from each labels data object and attaches the data to the given dataset.
4948
Updates the label's data object to have the same external_id and uid as the data row.
@@ -56,7 +55,7 @@ def add_to_dataset(self,
5655
dataset: labelbox dataset object to add the new data row to
5756
signer: A function that accepts bytes and returns a signed url.
5857
Returns:
59-
LabelCollection with updated references to new data rows
58+
LabelList with updated references to new data rows
6059
"""
6160
self._ensure_unique_external_ids()
6261
self.add_url_to_data(signer, max_concurrency=max_concurrency)
@@ -74,9 +73,9 @@ def add_to_dataset(self,
7473
label.data.uid = data_row_lookup[label.data.external_id]
7574
return self
7675

77-
def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelCollection":
76+
def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelList":
7877
"""
79-
Creates signed urls for all masks in the LabelCollection.
78+
Creates signed urls for all masks in the LabelList.
8079
Multiple masks can reference the same RasterData mask so this makes sure we only upload that url once.
8180
Only uploads url if one doesn't already exist.
8281
@@ -85,15 +84,15 @@ def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelCollection":
8584
max_concurrency: how many threads to use for uploading.
8685
Should be balanced to match the signing services capabilities.
8786
Returns:
88-
LabelCollection with updated references to the new mask urls
87+
LabelList with updated references to the new mask urls
8988
"""
9089
for row in self._apply_threaded(
9190
[label.add_url_to_masks for label in self._data], max_concurrency,
9291
signer):
9392
...
9493
return self
9594

96-
def add_url_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
95+
def add_url_to_data(self, signer, max_concurrency=20) -> "LabelList":
9796
"""
9897
Creates signed urls for the data
9998
Only uploads url if one doesn't already exist.
@@ -103,7 +102,7 @@ def add_url_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
103102
max_concurrency: how many threads to use for uploading.
104103
Should be balanced to match the signing services capabilities.
105104
Returns:
106-
LabelCollection with updated references to the new data urls
105+
LabelList with updated references to the new data urls
107106
"""
108107
for row in self._apply_threaded(
109108
[label.add_url_to_data for label in self._data], max_concurrency,
@@ -123,7 +122,7 @@ def _ensure_unique_external_ids(self) -> None:
123122
)
124123
external_ids.add(label.data.external_id)
125124

126-
def __iter__(self) -> "LabelCollection":
125+
def __iter__(self) -> "LabelList":
127126
self._index = 0
128127
return self
129128

@@ -156,15 +155,15 @@ class LabelGenerator(PrefetchGenerator):
156155
A container for interacting with a collection of labels.
157156
158157
Use this class if you have larger data. It is slightly harder to work with
159-
than the LabelCollection but will be much more memory efficient.
158+
than the LabelList but will be much more memory efficient.
160159
"""
161160

162161
def __init__(self, data: Generator[Label, None, None], *args, **kwargs):
163162
self._fns = {}
164163
super().__init__(data, *args, **kwargs)
165164

166-
def as_collection(self) -> "LabelCollection":
167-
return LabelCollection(data=list(self))
165+
def as_list(self) -> "LabelList":
166+
return LabelList(data=list(self))
168167

169168
def assign_schema_ids(
170169
self,
@@ -202,7 +201,7 @@ def add_to_dataset(self, dataset: "Entity.Dataset",
202201
Creates data rows from each labels data object and attaches the data to the given dataset.
203202
Updates the label's data object to have the same external_id and uid as the data row.
204203
205-
This is a lot slower than LabelCollection.add_to_dataset but also more memory efficient.
204+
This is a lot slower than LabelList.add_to_dataset but also more memory efficient.
206205
207206
Args:
208207
dataset: labelbox dataset object to add the new data row to
@@ -272,4 +271,4 @@ def __next__(self):
272271
return self._process(value)
273272

274273

275-
LabelContainer = Union[LabelCollection, LabelGenerator]
274+
LabelCollection = Union[LabelList, LabelGenerator]

labelbox/data/annotation_types/data/video.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ def create_url(self, signer: Callable[[bytes], str]) -> None:
119119
self.file_path = self.frames_to_video(self.frames)
120120
self.url = self.create_url(signer)
121121
else:
122-
raise ValueError(
123-
"One of url, im_bytes, file_path, numpy must not be None.")
122+
raise ValueError("One of url, file_path, frames must not be None.")
124123
return self.url
125124

126125
def frames_to_video(self,

labelbox/data/annotation_types/feature.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class FeatureSchema(BaseModel):
1111
Could be a annotation, a subclass, or an option.
1212
Schema ids might not be known when constructing these objects so both a name and schema id are valid.
1313
14-
Use `LabelCollection.assign_schema_ids` or `LabelGenerator.assign_schema_ids`
14+
Use `LabelList.assign_schema_ids` or `LabelGenerator.assign_schema_ids`
1515
to retroactively add schema ids by looking them up from the names.
1616
"""
1717
name: Optional[str] = None

labelbox/data/annotation_types/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def assign_schema_ids(
111111
Args:
112112
ontology_builder: The ontology that matches the feature names assigned to objects in this dataset
113113
Returns:
114-
LabelCollection. useful for chaining these modifying functions
114+
Label. useful for chaining these modifying functions
115115
"""
116116
tool_lookup, classification_lookup = self._get_feature_schema_lookup(
117117
ontology_builder)

labelbox/data/generator.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ class PrefetchGenerator:
3333
Useful for modifying the generator results based on data from a network
3434
"""
3535

36-
def __init__(self,
37-
data: Iterable[Any],
38-
prefetch_limit=20,
39-
max_concurrency=4):
36+
def __init__(self, data: Iterable[Any], prefetch_limit=20, num_executors=4):
4037
if isinstance(data, (list, tuple)):
4138
self._data = (r for r in data)
4239
else:
@@ -47,10 +44,10 @@ def __init__(self,
4744
self.completed_threads = 0
4845
# Can only iterate over once it the queue.get hangs forever.
4946
self.done = False
50-
self.max_concurrency = max_concurrency
51-
with ThreadPoolExecutor(max_workers=max_concurrency) as executor:
47+
self.num_executors = num_executors
48+
with ThreadPoolExecutor(max_workers=num_executors) as executor:
5249
self.futures = [
53-
executor.submit(self.fill_queue) for _ in range(max_concurrency)
50+
executor.submit(self.fill_queue) for _ in range(num_executors)
5451
]
5552

5653
def _process(self, value) -> Any:
@@ -78,7 +75,7 @@ def __next__(self) -> Any:
7875
value = self.queue.get()
7976
while value is None:
8077
self.completed_threads += 1
81-
if self.completed_threads == self.max_concurrency:
78+
if self.completed_threads == self.num_executors:
8279
self.done = True
8380
raise StopIteration
8481
value = self.queue.get()

tests/data/annotation_types/test_collection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from labelbox import DataRow
77
from labelbox.data.annotation_types.annotation import ObjectAnnotation
8-
from labelbox.data.annotation_types.collection import (LabelCollection,
8+
from labelbox.data.annotation_types.collection import (LabelList,
99
LabelGenerator)
1010
from labelbox.data.annotation_types.data.raster import RasterData
1111
from labelbox.data.annotation_types.geometry.line import Line
@@ -66,7 +66,7 @@ def test_generator(list_of_labels):
6666

6767
def test_conversion(list_of_labels):
6868
generator = LabelGenerator(list_of_labels)
69-
label_collection = generator.as_collection()
69+
label_collection = generator.as_list()
7070
assert len(label_collection) == len(list_of_labels)
7171
assert [x for x in label_collection] == list_of_labels
7272

@@ -87,7 +87,7 @@ def test_adding_schema_ids():
8787
tools=[Tool(Tool.Type.LINE, name=name, feature_schema_id=schema_id)])
8888
generator = LabelGenerator([label]).assign_schema_ids(ontology)
8989
assert next(generator).annotations[0].schema_id == schema_id
90-
labels = LabelCollection([label]).assign_schema_ids(ontology)
90+
labels = LabelList([label]).assign_schema_ids(ontology)
9191
assert next(labels).annotations[0].schema_id == schema_id
9292
assert labels[0].annotations[0].schema_id == schema_id
9393

@@ -106,7 +106,7 @@ def test_adding_urls(signer):
106106
3)).astype(np.uint8)),
107107
annotations=[])
108108
assert label.data.url != uuid
109-
labels = LabelCollection([label]).add_url_to_data(signer(uuid))
109+
labels = LabelList([label]).add_url_to_data(signer(uuid))
110110
assert label.data.url == uuid
111111
assert next(labels).data.url == uuid
112112
assert labels[0].data.url == uuid
@@ -133,7 +133,7 @@ def test_adding_to_dataset(signer):
133133
assert label.data.url != uuid
134134
assert label.data.external_id == None
135135
assert label.data.uid != dataset.uid
136-
labels = LabelCollection([label]).add_to_dataset(dataset, signer(uuid))
136+
labels = LabelList([label]).add_to_dataset(dataset, signer(uuid))
137137
assert label.data.url == uuid
138138
assert label.data.external_id != None
139139
assert label.data.uid == dataset.uid
@@ -169,6 +169,6 @@ def test_adding_to_masks(signer):
169169
color=[255, 255, 255]))
170170
])
171171
assert label.annotations[0].value.mask.url != uuid
172-
labels = LabelCollection([label]).add_url_to_masks(signer(uuid))
172+
labels = LabelList([label]).add_url_to_masks(signer(uuid))
173173
assert next(labels).annotations[0].value.mask.url == uuid
174174
assert labels[0].annotations[0].value.mask.url == uuid

0 commit comments

Comments
 (0)