Skip to content

Commit f9a93d9

Browse files
committed
updates
1 parent bf4b3e4 commit f9a93d9

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

labelbox/data/annotation_types/feature.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ class FeatureSchema(BaseModel):
1010
Class that represents a feature schema.
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.
13-
14-
Use `LabelList.assign_feature_schema_ids` or `LabelGenerator.assign_feature_schema_ids`
15-
to retroactively add schema ids by looking them up from the names.
1613
"""
1714
name: Optional[str] = None
1815
feature_schema_id: Optional[Cuid] = None
@@ -27,8 +24,8 @@ def must_set_one(cls, values):
2724

2825
def dict(self, *args, **kwargs):
2926
res = super().dict(*args, **kwargs)
30-
if res['name'] is None:
27+
if 'name' in res and res['name'] is None:
3128
res.pop('name')
32-
if res['feature_schema_id'] is None:
33-
res.pop('feature_schema_id')
29+
if 'featureSchemaId' in res and res.featureSchemaId is None:
30+
res.pop('featureSchemaId')
3431
return res

labelbox/data/annotation_types/label.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import defaultdict
22
from typing import Any, Callable, Dict, List, Union, Optional
3+
import warnings
34

45
from pydantic import BaseModel, validator
56

@@ -136,6 +137,9 @@ def assign_feature_schema_ids(
136137
ontology_builder: The ontology that matches the feature names assigned to objects in this dataset
137138
Returns:
138139
Label. useful for chaining these modifying functions
140+
141+
Warning: assign_feature_schema_ids is now obsolete, you can
142+
now use names directly without having to lookup schema_ids.
139143
"""
140144
tool_lookup, classification_lookup = get_feature_schema_lookup(
141145
ontology_builder)

labelbox/data/serialization/ndjson/base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,13 @@ def validate_name(cls, v, values):
4444
@validator('schema_id', pre=True, always=True)
4545
def validate_id(cls, v, values):
4646
if v is None and 'name' not in values:
47-
raise ValueError(
48-
"Schema ids or names are not set. Use `LabelGenerator.assign_feature_schema_ids`, `LabelList.assign_feature_schema_ids`, or `Label.assign_feature_schema_ids`."
49-
)
47+
raise ValueError("Schema id or name are not set. Set either one.")
5048
return v
5149

5250
def dict(self, *args, **kwargs):
5351
res = super().dict(*args, **kwargs)
54-
if res['name'] is None:
52+
if 'name' in res and res['name'] is None:
5553
res.pop('name')
56-
if res['schemaId'] is None:
54+
if 'schemaId' in res and res['schemaId'] is None:
5755
res.pop('schemaId')
5856
return res

labelbox/data/serialization/ndjson/classification.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from tkinter import N
12
from typing import Any, Dict, List, Union, Optional
23

34
from pydantic import BaseModel, Field, validator
@@ -29,9 +30,9 @@ def validate_id(cls, v, values):
2930

3031
def dict(self, *args, **kwargs):
3132
res = super().dict(*args, **kwargs)
32-
if res['name'] is None:
33+
if 'name' in res and res['name'] is None:
3334
res.pop('name')
34-
if res['schemaId'] is None:
35+
if 'schemaId' in res and res['schemaId'] is None:
3536
res.pop('schemaId')
3637
return res
3738

@@ -153,7 +154,8 @@ class NDRadio(NDAnnotation, NDRadioSubclass, VideoSupported):
153154
def from_common(cls, radio: Radio, name: str, feature_schema_id: Cuid,
154155
extra: Dict[str, Any], data: Union[VideoData, TextData,
155156
ImageData]) -> "NDRadio":
156-
return cls(answer=NDFeature(schema_id=radio.answer.feature_schema_id),
157+
return cls(answer=NDFeature(name=radio.answer.name,
158+
schema_id=radio.answer.feature_schema_id),
157159
data_row={'id': data.uid},
158160
name=name,
159161
schema_id=feature_schema_id,
@@ -172,7 +174,7 @@ def from_common(
172174
raise TypeError(
173175
f"Unable to convert object to MAL format. `{type(annotation.value)}`"
174176
)
175-
return classify_obj.from_common(annotation.value,
177+
return classify_obj.from_common(annotation.value, annotation.name,
176178
annotation.feature_schema_id)
177179

178180
@staticmethod

labelbox/data/serialization/ndjson/label.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def _generate_annotations(
5050
for annotation in annotations:
5151
if isinstance(annotation, NDSegments):
5252
annots.extend(
53-
NDSegments.to_common(annotation, annotation.schema_id))
53+
NDSegments.to_common(annotation, annotation.name,
54+
annotation.schema_id))
5455

5556
elif isinstance(annotation, NDObjectType.__args__):
5657
annots.append(NDObject.to_common(annotation))
@@ -92,10 +93,12 @@ def _create_video_annotations(
9293

9394
video_annotations = defaultdict(list)
9495
for annot in label.annotations:
96+
# print(dict(annot))
9597
if isinstance(
9698
annot,
9799
(VideoClassificationAnnotation, VideoObjectAnnotation)):
98-
video_annotations[annot.schema_id or annot.name].append(annot)
100+
video_annotations[annot.feature_schema_id or
101+
annot.name].append(annot)
99102

100103
for annotation_group in video_annotations.values():
101104
consecutive_frames = cls._get_consecutive_frames(

tests/data/annotation_types/classification/test_classification.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ def test_subclass():
4343
classification = ClassificationAnnotation(value=Text(answer=answer))
4444
classification = ClassificationAnnotation(value=Text(answer=answer),
4545
name=name)
46-
assert classification.dict() == {
46+
assert classification.dict(by_alias=True) == {
4747
'name': name,
48+
'feature_schema_id': None,
4849
'extra': {},
4950
'value': {
5051
'answer': answer
@@ -92,6 +93,7 @@ def test_radio():
9293
assert classification.dict() == {
9394
'answer': {
9495
'name': answer.name,
96+
'feature_schema_id': None,
9597
'extra': {}
9698
}
9799
}
@@ -106,6 +108,7 @@ def test_radio():
106108
'value': {
107109
'answer': {
108110
'name': answer.name,
111+
'feature_schema_id': None,
109112
'extra': {}
110113
}
111114
}
@@ -127,6 +130,7 @@ def test_checklist():
127130
assert classification.dict() == {
128131
'answer': [{
129132
'name': answer.name,
133+
'feature_schema_id': None,
130134
'extra': {}
131135
}]
132136
}
@@ -142,6 +146,7 @@ def test_checklist():
142146
'value': {
143147
'answer': [{
144148
'name': answer.name,
149+
'feature_schema_id': None,
145150
'extra': {}
146151
}]
147152
},
@@ -160,7 +165,13 @@ def test_dropdown():
160165
with pytest.raises(ValidationError):
161166
classification = Dropdown(answer=answer)
162167
classification = Dropdown(answer=[answer])
163-
assert classification.dict() == {'answer': [{'name': '1', 'extra': {}}]}
168+
assert classification.dict() == {
169+
'answer': [{
170+
'name': '1',
171+
'feature_schema_id': None,
172+
'extra': {}
173+
}]
174+
}
164175
classification = ClassificationAnnotation(
165176
value=Dropdown(answer=[answer]),
166177
feature_schema_id=feature_schema_id,
@@ -172,6 +183,7 @@ def test_dropdown():
172183
'value': {
173184
'answer': [{
174185
'name': answer.name,
186+
'feature_schema_id': None,
175187
'extra': {}
176188
}]
177189
}

0 commit comments

Comments
 (0)