Skip to content

Commit 55a81a6

Browse files
author
Matt Sokoloff
committed
Merge branch 'ms/core-annotation-types' of https://github.com/Labelbox/labelbox-python into ms/annotation-examples
2 parents 8403021 + 87b0f03 commit 55a81a6

File tree

5 files changed

+44
-123
lines changed

5 files changed

+44
-123
lines changed

.github/workflows/python-package.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,21 @@ jobs:
4747
uses: AlexanderMelde/yapf-action@master
4848
with:
4949
args: --verbose --recursive --parallel --style "google"
50-
50+
- name: dependencies
51+
run: |
52+
sudo apt-get -y update
53+
sudo apt install -y libsm6 \
54+
libxext6 \
55+
ffmpeg \
56+
libfontconfig1 \
57+
libxrender1 \
58+
libgl1-mesa-glx
5159
- name: install labelbox package
5260
run: |
53-
python setup.py install
61+
python -m pip install --upgrade pip
62+
python -m pip install .
5463
- name: mypy
5564
run: |
56-
python -m pip install --upgrade pip
5765
pip install mypy==0.782
5866
mypy -p labelbox --pretty --show-error-codes
5967
- name: Install package and test dependencies

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
FROM python:3.7
22

33
RUN pip install pytest pytest-cases
4-
RUN apt-get -y update && apt install -y libsm6 libxext6 ffmpeg libfontconfig1 libxrender1 libgl1-mesa-glx
4+
RUN apt-get -y update
5+
RUN apt install -y libsm6 \
6+
libxext6 \
7+
ffmpeg \
8+
libfontconfig1 \
9+
libxrender1 \
10+
libgl1-mesa-glx
511

612
WORKDIR /usr/src/labelbox
713
COPY requirements.txt /usr/src/labelbox
814
RUN pip install -r requirements.txt
915
COPY . /usr/src/labelbox
1016

11-
1217
RUN python setup.py install

labelbox/data/annotation_types/annotation.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@
99
class BaseAnnotation(FeatureSchema):
1010
""" Base annotation class. Shouldn't be directly instantiated
1111
"""
12-
classifications: List["ClassificationAnnotation"] = []
13-
extra: Dict[str, Any] = {}
14-
1512

16-
class ObjectAnnotation(BaseAnnotation):
17-
"""Class representing objects annotations (non classifications or annotations that have a location)
18-
"""
19-
value: Union[TextEntity, Geometry]
13+
extra: Dict[str, Any] = {}
2014

2115

2216
class ClassificationAnnotation(BaseAnnotation):
2317
"""Class represneting classification annotations (annotations that don't have a location) """
2418
value: Union[Text, Checklist, Radio, Dropdown]
2519

2620

27-
ClassificationAnnotation.update_forward_refs()
21+
class ObjectAnnotation(BaseAnnotation):
22+
"""Class representing objects annotations (non classifications or annotations that have a location)
23+
"""
24+
value: Union[TextEntity, Geometry]
25+
classifications: List[ClassificationAnnotation] = []
2826

2927

3028
class VideoObjectAnnotation(ObjectAnnotation):
@@ -47,7 +45,3 @@ class VideoClassificationAnnotation(ClassificationAnnotation):
4745
frame: The frame index that this annotation corresponds to
4846
"""
4947
frame: int
50-
51-
52-
VideoObjectAnnotation.update_forward_refs()
53-
ObjectAnnotation.update_forward_refs()

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"backoff==1.10.0",
2424
"backports-datetime-fromisoformat==1.0.0; python_version < '3.7.0'",
2525
"dataclasses==0.7; python_version < '3.7.0'", "ndjson==0.3.1",
26-
"requests>=2.22.0", "google-api-core>=1.22.1", "pydantic>=1.8,<2.0", "shapely", "geojson", "numpy", "rasterio", "PILLOW", "opencv-python", "typeguard", "tqdm"
26+
"requests>=2.22.0", "google-api-core>=1.22.1", "pydantic>=1.8,<2.0",
27+
"shapely", "geojson", "numpy", "rasterio", "PILLOW", "opencv-python",
28+
"typeguard", "tqdm"
2729
],
2830
classifiers=[
2931
'Development Status :: 3 - Alpha',

tests/data/annotation_types/classification/test_classification.py

Lines changed: 17 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ def test_subclass():
4949
'extra': {},
5050
'value': {
5151
'answer': answer
52-
},
53-
'classifications': []
52+
}
5453
}
5554
classification = ClassificationAnnotation(value=Text(answer=answer),
5655
name=name,
@@ -62,7 +61,6 @@ def test_subclass():
6261
'value': {
6362
'answer': answer
6463
},
65-
'classifications': [],
6664
'name': name
6765
}
6866
classification = ClassificationAnnotation(value=Text(answer=answer),
@@ -74,37 +72,7 @@ def test_subclass():
7472
'extra': {},
7573
'value': {
7674
'answer': answer
77-
},
78-
'classifications': []
79-
}
80-
81-
classification = ClassificationAnnotation(value=Text(answer=answer),
82-
name=name,
83-
schema_id=schema_id,
84-
classifications=[
85-
ClassificationAnnotation(
86-
value=Text(answer=answer),
87-
name=name)
88-
])
89-
90-
assert classification.dict() == {
91-
'name':
92-
name,
93-
'extra': {},
94-
'schema_id':
95-
schema_id,
96-
'value': {
97-
'answer': answer
98-
},
99-
'classifications': [{
100-
'name': name,
101-
'extra': {},
102-
'schema_id': None,
103-
'value': {
104-
'answer': answer
105-
},
106-
'classifications': []
107-
}]
75+
}
10876
}
10977

11078

@@ -127,39 +95,20 @@ def test_radio():
12795
'extra': {}
12896
}
12997
}
130-
classification = ClassificationAnnotation(
131-
value=Radio(answer=answer),
132-
schema_id=schema_id,
133-
name=name,
134-
classifications=[
135-
ClassificationAnnotation(value=Radio(answer=answer), name=name)
136-
])
98+
classification = ClassificationAnnotation(value=Radio(answer=answer),
99+
schema_id=schema_id,
100+
name=name)
137101
assert classification.dict() == {
138-
'name':
139-
name,
140-
'schema_id':
141-
schema_id,
102+
'name': name,
103+
'schema_id': schema_id,
142104
'extra': {},
143105
'value': {
144106
'answer': {
145107
'name': answer.name,
146108
'schema_id': None,
147109
'extra': {}
148110
}
149-
},
150-
'classifications': [{
151-
'name': name,
152-
'schema_id': None,
153-
'extra': {},
154-
'value': {
155-
'answer': {
156-
'name': answer.name,
157-
'schema_id': None,
158-
'extra': {}
159-
}
160-
},
161-
'classifications': []
162-
}]
111+
}
163112
}
164113

165114

@@ -186,15 +135,10 @@ def test_checklist():
186135
value=Checklist(answer=[answer]),
187136
schema_id=schema_id,
188137
name=name,
189-
classifications=[
190-
ClassificationAnnotation(value=Checklist(answer=[answer]),
191-
name=name)
192-
])
138+
)
193139
assert classification.dict() == {
194-
'name':
195-
name,
196-
'schema_id':
197-
schema_id,
140+
'name': name,
141+
'schema_id': schema_id,
198142
'extra': {},
199143
'value': {
200144
'answer': [{
@@ -203,19 +147,6 @@ def test_checklist():
203147
'extra': {}
204148
}]
205149
},
206-
'classifications': [{
207-
'name': name,
208-
'schema_id': None,
209-
'extra': {},
210-
'value': {
211-
'answer': [{
212-
'name': answer.name,
213-
'schema_id': None,
214-
'extra': {}
215-
}]
216-
},
217-
'classifications': []
218-
}]
219150
}
220151

221152

@@ -238,37 +169,18 @@ def test_dropdown():
238169
'extra': {}
239170
}]
240171
}
241-
classification = ClassificationAnnotation(
242-
value=Dropdown(answer=[answer]),
243-
schema_id=schema_id,
244-
name=name,
245-
classifications=[
246-
ClassificationAnnotation(value=Dropdown(answer=[answer]), name=name)
247-
])
172+
classification = ClassificationAnnotation(value=Dropdown(answer=[answer]),
173+
schema_id=schema_id,
174+
name=name)
248175
assert classification.dict() == {
249-
'name':
250-
name,
251-
'schema_id':
252-
schema_id,
176+
'name': name,
177+
'schema_id': schema_id,
253178
'extra': {},
254179
'value': {
255180
'answer': [{
256181
'name': answer.name,
257182
'schema_id': None,
258183
'extra': {}
259184
}]
260-
},
261-
'classifications': [{
262-
'name': name,
263-
'schema_id': None,
264-
'extra': {},
265-
'value': {
266-
'answer': [{
267-
'name': answer.name,
268-
'schema_id': None,
269-
'extra': {}
270-
}]
271-
},
272-
'classifications': []
273-
}]
185+
}
274186
}

0 commit comments

Comments
 (0)