Skip to content

Commit 32b15a8

Browse files
author
Matt Sokoloff
committed
label container notebook
1 parent 8b6b620 commit 32b15a8

File tree

18 files changed

+537
-366
lines changed

18 files changed

+537
-366
lines changed

examples/annotation_types/annotation_type_basics.ipynb

Lines changed: 384 additions & 135 deletions
Large diffs are not rendered by default.

examples/annotation_types/label_containers.ipynb

Lines changed: 103 additions & 185 deletions
Large diffs are not rendered by default.

labelbox/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
from labelbox.schema.asset_attachment import AssetAttachment
1717
from labelbox.schema.webhook import Webhook
1818
from labelbox.schema.prediction import Prediction, PredictionModel
19-
from labelbox.schema.ontology import Ontology
19+
from labelbox.schema.ontology import Ontology, OntologyBuilder, Classification, Option, Tool
2020
from labelbox.schema.role import Role, ProjectRole
2121
from labelbox.schema.invite import Invite, InviteLimit

labelbox/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,3 +503,4 @@ def get_roles(self):
503503
Roles are used for user management.
504504
"""
505505
return role.get_roles(self)
506+

labelbox/data/annotation_types/collection.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from tqdm import tqdm
77

8-
from labelbox.schema.ontology import OntologyBuilder
8+
from labelbox import OntologyBuilder
99
from labelbox.orm.model import Entity
1010
from ..generator import PrefetchGenerator
1111
from .label import Label
@@ -62,7 +62,7 @@ def add_to_dataset(self,
6262
upload_task = dataset.create_data_rows([{
6363
'row_data': label.data.url,
6464
'external_id': label.data.external_id
65-
} for label in self])
65+
} for label in self._data])
6666
upload_task.wait_till_done()
6767

6868
data_row_lookup = {
@@ -128,6 +128,7 @@ def __iter__(self) -> "LabelCollection":
128128

129129
def __next__(self) -> Label:
130130
if self._index == len(self._data):
131+
self._index = 0
131132
raise StopIteration
132133

133134
value = self._data[self._index]

labelbox/data/annotation_types/label.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pydantic import BaseModel
44

5-
from labelbox.schema.ontology import Classification as OClassification, OntologyBuilder, Option
5+
from labelbox import Classification as OClassification, OntologyBuilder, Option
66
from labelbox.orm.model import Entity
77
from .classification import ClassificationAnswer
88
from .data import VideoData, TextData, RasterData

labelbox/data/serialization/labelbox_v1/classification.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def from_common(cls, radio: Radio, schema_id: Cuid, **extra) -> "LBV1Radio":
3030
answer=LBV1ClassificationAnswer(
3131
schema_id=radio.answer.schema_id,
3232
title=radio.answer.name,
33-
value=radio.answer.extra['value'],
34-
feature_id=radio.answer.extra['feature_id']),
33+
value=radio.answer.extra.get('value'),
34+
feature_id=radio.answer.extra.get('feature_id')),
3535
**extra)
3636

3737

@@ -56,8 +56,8 @@ def from_common(cls, checklist: Checklist, schema_id: Cuid,
5656
LBV1ClassificationAnswer(
5757
schema_id=answer.schema_id,
5858
title=answer.name,
59-
value=answer.extra['value'],
60-
feature_id=answer.extra['feature_id'])
59+
value=answer.extra.get('value'),
60+
feature_id=answer.extra.get('feature_id'))
6161
for answer in checklist.answer
6262
],
6363
**extra)

labelbox/data/serialization/labelbox_v1/converter.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
from requests.exceptions import HTTPError
22
import labelbox
3-
from typing import Any, Callable, Dict, Generator, Iterable
3+
from typing import Any, Dict, Generator, Iterable
44
import logging
55

66
import ndjson
77
import requests
88
from google.api_core import retry
99

1010
from .label import LBV1Label
11-
from ...annotation_types.collection import (LabelData, LabelGenerator,
11+
from ...annotation_types.collection import (LabelContainer, LabelGenerator,
1212
PrefetchGenerator)
1313

1414
logger = logging.getLogger(__name__)
@@ -53,9 +53,7 @@ def label_generator():
5353

5454
@staticmethod
5555
def serialize(
56-
labels: LabelData,
57-
signer: Callable[[bytes],
58-
str]) -> Generator[Dict[str, Any], None, None]:
56+
labels: LabelContainer) -> Generator[Dict[str, Any], None, None]:
5957
"""
6058
Converts a labelbox common object to the labelbox json export format
6159
@@ -65,7 +63,7 @@ def serialize(
6563
A generator for accessing the labelbox json export representation of the data
6664
"""
6765
for label in labels:
68-
res = LBV1Label.from_common(label, signer)
66+
res = LBV1Label.from_common(label)
6967
yield res.dict(by_alias=True)
7068

7169

labelbox/data/serialization/labelbox_v1/label.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from labelbox.utils import camel_case
2-
from typing import Callable, List, Optional, Union
2+
from typing import List, Optional, Union
33

44
from pydantic import BaseModel, Field
55

@@ -158,16 +158,21 @@ def to_common(self) -> Label:
158158
})
159159

160160
@classmethod
161-
def from_common(cls, label: Label, signer: Callable[[bytes], str]):
161+
def from_common(cls, label: Label):
162162
if isinstance(label.annotations[0],
163163
(VideoObjectAnnotation, VideoClassificationAnnotation)):
164164
label_ = LBV1LabelAnnotationsVideo.from_common(label.annotations)
165165
else:
166166
label_ = LBV1LabelAnnotations.from_common(label.annotations)
167167

168+
if label.data.url is None:
169+
raise ValueError("Url attribute required for serializing data objects. "
170+
"Use <LabelCollection,LabelGenerator>.add_url_to_data "
171+
"or <LabelCollection,LabelGenerator>.add_to_dataset")
172+
168173
return LBV1Label(label=label_,
169174
data_row_id=label.data.uid,
170-
row_data=label.data.create_url(signer),
175+
row_data=label.data.url,
171176
external_id=label.data.external_id,
172177
**label.extra)
173178

labelbox/schema/ontology.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
import abc
21
from dataclasses import dataclass, field
3-
from enum import Enum, auto
2+
from enum import Enum
43
import colorsys
54

6-
from typing import Any, Callable, Dict, List, Optional, Union
5+
from typing import Any, Dict, List, Optional, Union
76

87
from labelbox.schema.project import Project
9-
from labelbox.orm import query
10-
from labelbox.orm.db_object import DbObject, Updateable, BulkDeletable
11-
from labelbox.orm.model import Entity, Field, Relationship
12-
from labelbox.utils import snake_case, camel_case
8+
from labelbox.orm.db_object import DbObject
9+
from labelbox.orm.model import Field, Relationship
1310
from labelbox.exceptions import InconsistentOntologyException
1411

1512

@@ -335,7 +332,7 @@ def _update_colors(self):
335332
self.tools[index].color = '#%02x%02x%02x' % rgb_color
336333

337334
@classmethod
338-
def from_project(cls, project: Project):
335+
def from_project(cls, project: "Project"):
339336
ontology = project.ontology().normalized
340337
return OntologyBuilder.from_dict(ontology)
341338

0 commit comments

Comments
 (0)