Skip to content

[PLT-1490] Removed project.setup #1843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions libs/labelbox/src/labelbox/schema/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,18 @@ class OntologyBuilder:
There are no required instantiation arguments.

To create an ontology, use the asdict() method after fully building your
ontology within this class, and inserting it into project.setup() as the
"labeling_frontend_options" parameter.
ontology within this class, and inserting it into client.create_ontology() as the
"normalized" parameter.

Example:
builder = OntologyBuilder()
...
frontend = list(client.get_labeling_frontends())[0]
project.setup(frontend, builder.asdict())
>>> builder = OntologyBuilder()
>>> ...
>>> ontology = client.create_ontology(
>>> "Ontology from new features",
>>> ontology_builder.asdict(),
>>> media_type=lb.MediaType.Image,
>>> )
>>> project.connect_ontology(ontology)

attributes:
tools: (list)
Expand Down
28 changes: 0 additions & 28 deletions libs/labelbox/src/labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,34 +684,6 @@ def connect_ontology(self, ontology) -> None:
timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
self.update(setup_complete=timestamp)

def setup(self, labeling_frontend, labeling_frontend_options) -> None:
"""This method will associate default labeling frontend with the project and create an ontology based on labeling_frontend_options.

Args:
labeling_frontend (LabelingFrontend): Do not use, this parameter is deprecated. We now associate the default labeling frontend with the project.
labeling_frontend_options (dict or str): Labeling frontend options,
a.k.a. project ontology. If given a `dict` it will be converted
to `str` using `json.dumps`.
"""

warnings.warn("This method is deprecated use connect_ontology instead.")
if labeling_frontend is not None:
warnings.warn(
"labeling_frontend parameter will not be used to create a new labeling frontend."
)

if self.is_chat_evaluation() or self.is_prompt_response():
warnings.warn("""
This project is a live chat evaluation project or prompt and response generation project.
Editor was setup automatically.
""")
return

self._connect_default_labeling_front_end(labeling_frontend_options)

timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
self.update(setup_complete=timestamp)

def _connect_default_labeling_front_end(self, ontology_as_dict: dict):
labeling_frontend = self.labeling_frontend()
if (
Expand Down
59 changes: 28 additions & 31 deletions libs/labelbox/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def configured_project_with_label(
[data_row.uid], # sample of data row objects
5, # priority between 1(Highest) - 5(lowest)
)
ontology = _setup_ontology(project)
ontology = _setup_ontology(project, client)
label = _create_label(
project, data_row, ontology, wait_for_label_processing
)
Expand Down Expand Up @@ -699,20 +699,19 @@ def create_label():
return label


def _setup_ontology(project):
editor = list(
project.client.get_labeling_frontends(
where=LabelingFrontend.name == "editor"
)
)[0]
def _setup_ontology(project: Project, client: Client):
ontology_builder = OntologyBuilder(
tools=[
Tool(tool=Tool.Type.BBOX, name="test-bbox-class"),
]
)
project.setup(editor, ontology_builder.asdict())
# TODO: ontology may not be synchronous after setup. remove sleep when api is more consistent
time.sleep(2)
ontology = client.create_ontology(
name="ontology with features",
media_type=MediaType.Image,
normalized=ontology_builder.asdict(),
)
project.connect_ontology(ontology)

return OntologyBuilder.from_project(project)


Expand Down Expand Up @@ -754,7 +753,7 @@ def configured_batch_project_with_label(
project.create_batch("test-batch", data_rows)
project.data_row_ids = data_rows

ontology = _setup_ontology(project)
ontology = _setup_ontology(project, client)
label = _create_label(
project, data_row, ontology, wait_for_label_processing
)
Expand Down Expand Up @@ -786,7 +785,7 @@ def configured_batch_project_with_multiple_datarows(
batch_name = f"batch {uuid.uuid4()}"
project.create_batch(batch_name, global_keys=global_keys)

ontology = _setup_ontology(project)
ontology = _setup_ontology(project, client)
for datarow in data_rows:
_create_label(project, datarow, ontology, wait_for_label_processing)

Expand Down Expand Up @@ -1023,11 +1022,11 @@ def _upload_invalid_data_rows_for_dataset(dataset: Dataset):

@pytest.fixture
def configured_project(
project_with_empty_ontology, initial_dataset, rand_gen, image_url
project_with_one_feature_ontology, initial_dataset, rand_gen, image_url
):
dataset = initial_dataset
data_row_id = dataset.create_data_row(row_data=image_url).uid
project = project_with_empty_ontology
project = project_with_one_feature_ontology

batch = project.create_batch(
rand_gen(str),
Expand All @@ -1042,20 +1041,21 @@ def configured_project(


@pytest.fixture
def project_with_empty_ontology(project):
editor = list(
project.client.get_labeling_frontends(
where=LabelingFrontend.name == "editor"
)
)[0]
empty_ontology = {"tools": [], "classifications": []}
project.setup(editor, empty_ontology)
def project_with_one_feature_ontology(project, client: Client):
tools = [
Tool(tool=Tool.Type.BBOX, name="test-bbox-class").asdict(),
]
empty_ontology = {"tools": tools, "classifications": []}
ontology = client.create_ontology(
"empty ontology", empty_ontology, MediaType.Image
)
project.connect_ontology(ontology)
yield project


@pytest.fixture
def configured_project_with_complex_ontology(
client, initial_dataset, rand_gen, image_url, teardown_helpers
client: Client, initial_dataset, rand_gen, image_url, teardown_helpers
):
project = client.create_project(
name=rand_gen(str),
Expand All @@ -1072,19 +1072,12 @@ def configured_project_with_complex_ontology(
)
project.data_row_ids = data_row_ids

editor = list(
project.client.get_labeling_frontends(
where=LabelingFrontend.name == "editor"
)
)[0]

ontology = OntologyBuilder()
tools = [
Tool(tool=Tool.Type.BBOX, name="test-bbox-class"),
Tool(tool=Tool.Type.LINE, name="test-line-class"),
Tool(tool=Tool.Type.POINT, name="test-point-class"),
Tool(tool=Tool.Type.POLYGON, name="test-polygon-class"),
Tool(tool=Tool.Type.NER, name="test-ner-class"),
]

options = [
Expand Down Expand Up @@ -1116,7 +1109,11 @@ def configured_project_with_complex_ontology(
for c in classifications:
ontology.add_classification(c)

project.setup(editor, ontology.asdict())
ontology = client.create_ontology(
"complex image ontology", ontology.asdict(), MediaType.Image
)

project.connect_ontology(ontology)

yield [project, data_row]
teardown_helpers.teardown_project_labels_ontology_feature_schemas(project)
Expand Down
Loading
Loading