13
13
logger = logging .getLogger (__name__ )
14
14
15
15
16
- class LabelCollection :
16
+ class LabelList :
17
17
"""
18
18
A container for interacting with a collection of labels.
19
19
Less memory efficient than LabelGenerator but more performant and convenient to use.
@@ -24,16 +24,16 @@ def __init__(self, data: Iterable[Label]):
24
24
self ._data = data
25
25
self ._index = 0
26
26
27
- def assign_schema_ids (
28
- self , ontology_builder : OntologyBuilder ) -> "LabelCollection " :
27
+ def assign_schema_ids (self ,
28
+ ontology_builder : OntologyBuilder ) -> "LabelList " :
29
29
"""
30
30
Adds schema ids to all FeatureSchema objects in the Labels.
31
31
This is necessary for MAL.
32
32
33
33
Args:
34
- 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
35
35
Returns:
36
- LabelCollection . useful for chaining these modifying functions
36
+ LabelList . useful for chaining these modifying functions
37
37
"""
38
38
for label in self ._data :
39
39
label .assign_schema_ids (ontology_builder )
@@ -42,7 +42,7 @@ def assign_schema_ids(
42
42
def add_to_dataset (self ,
43
43
dataset : "Entity.Dataset" ,
44
44
signer : Callable [[bytes ], str ],
45
- max_concurrency = 20 ) -> "LabelCollection " :
45
+ max_concurrency = 20 ) -> "LabelList " :
46
46
"""
47
47
Creates data rows from each labels data object and attaches the data to the given dataset.
48
48
Updates the label's data object to have the same external_id and uid as the data row.
@@ -55,7 +55,7 @@ def add_to_dataset(self,
55
55
dataset: labelbox dataset object to add the new data row to
56
56
signer: A function that accepts bytes and returns a signed url.
57
57
Returns:
58
- LabelCollection with updated references to new data rows
58
+ LabelList with updated references to new data rows
59
59
"""
60
60
self ._ensure_unique_external_ids ()
61
61
self .add_url_to_data (signer , max_concurrency = max_concurrency )
@@ -73,9 +73,9 @@ def add_to_dataset(self,
73
73
label .data .uid = data_row_lookup [label .data .external_id ]
74
74
return self
75
75
76
- def add_url_to_masks (self , signer , max_concurrency = 20 ) -> "LabelCollection " :
76
+ def add_url_to_masks (self , signer , max_concurrency = 20 ) -> "LabelList " :
77
77
"""
78
- Creates signed urls for all masks in the LabelCollection .
78
+ Creates signed urls for all masks in the LabelList .
79
79
Multiple masks can reference the same RasterData mask so this makes sure we only upload that url once.
80
80
Only uploads url if one doesn't already exist.
81
81
@@ -84,15 +84,15 @@ def add_url_to_masks(self, signer, max_concurrency=20) -> "LabelCollection":
84
84
max_concurrency: how many threads to use for uploading.
85
85
Should be balanced to match the signing services capabilities.
86
86
Returns:
87
- LabelCollection with updated references to the new mask urls
87
+ LabelList with updated references to the new mask urls
88
88
"""
89
89
for row in self ._apply_threaded (
90
90
[label .add_url_to_masks for label in self ._data ], max_concurrency ,
91
91
signer ):
92
92
...
93
93
return self
94
94
95
- def add_url_to_data (self , signer , max_concurrency = 20 ) -> "LabelCollection " :
95
+ def add_url_to_data (self , signer , max_concurrency = 20 ) -> "LabelList " :
96
96
"""
97
97
Creates signed urls for the data
98
98
Only uploads url if one doesn't already exist.
@@ -102,7 +102,7 @@ def add_url_to_data(self, signer, max_concurrency=20) -> "LabelCollection":
102
102
max_concurrency: how many threads to use for uploading.
103
103
Should be balanced to match the signing services capabilities.
104
104
Returns:
105
- LabelCollection with updated references to the new data urls
105
+ LabelList with updated references to the new data urls
106
106
"""
107
107
for row in self ._apply_threaded (
108
108
[label .add_url_to_data for label in self ._data ], max_concurrency ,
@@ -122,7 +122,7 @@ def _ensure_unique_external_ids(self) -> None:
122
122
)
123
123
external_ids .add (label .data .external_id )
124
124
125
- def __iter__ (self ) -> "LabelCollection " :
125
+ def __iter__ (self ) -> "LabelList " :
126
126
self ._index = 0
127
127
return self
128
128
@@ -155,15 +155,15 @@ class LabelGenerator(PrefetchGenerator):
155
155
A container for interacting with a collection of labels.
156
156
157
157
Use this class if you have larger data. It is slightly harder to work with
158
- than the LabelCollection but will be much more memory efficient.
158
+ than the LabelList but will be much more memory efficient.
159
159
"""
160
160
161
161
def __init__ (self , data : Generator [Label , None , None ], * args , ** kwargs ):
162
162
self ._fns = {}
163
163
super ().__init__ (data , * args , ** kwargs )
164
164
165
- def as_collection (self ) -> "LabelCollection " :
166
- return LabelCollection (data = list (self ))
165
+ def as_list (self ) -> "LabelList " :
166
+ return LabelList (data = list (self ))
167
167
168
168
def assign_schema_ids (
169
169
self , ontology_builder : OntologyBuilder ) -> "LabelGenerator" :
@@ -200,7 +200,7 @@ def add_to_dataset(self, dataset: "Entity.Dataset",
200
200
Creates data rows from each labels data object and attaches the data to the given dataset.
201
201
Updates the label's data object to have the same external_id and uid as the data row.
202
202
203
- This is a lot slower than LabelCollection .add_to_dataset but also more memory efficient.
203
+ This is a lot slower than LabelList .add_to_dataset but also more memory efficient.
204
204
205
205
Args:
206
206
dataset: labelbox dataset object to add the new data row to
@@ -270,4 +270,4 @@ def __next__(self):
270
270
return self ._process (value )
271
271
272
272
273
- LabelContainer = Union [LabelCollection , LabelGenerator ]
273
+ LabelCollection = Union [LabelList , LabelGenerator ]
0 commit comments