Uploading historic ground-truth labels to New project WITH Existing Ontology [SOLVED]

i have been working on uploading data rows and labels from a prior annotation tool, so that we can unify all our labeling data in the Labelbox app.

I was able to convert the lables and upload them successfully following SDK tutorial for Image Annotation Import labelbox-python/image.ipynb at develop · Labelbox/labelbox-python · GitHub

However, the issue is that it always forced me to setup the project with a ‘new’ Ontology and I wanted to use an existing one - such that all my desired labels in Labelbox will share the same ontology and can be used in the same “Model Run” - this is critical.
I know that many Projects can be configured with the same editor Ontology in the Labelbox App, so I am not sure why I can’t do this from the SDK.

The tutorial shows using a new ontology, but I was able to serialize an existing Ontology, after inspecting the .asdict() method for the OntologyBuilder source code - but even this didn’t work.
It still ended up creating a new editor Ontology with the name of the new project.
See the (DEFAULT METHOD) and my (WORK-AROUND) method in the code snippet below. This code runs with no errors, but doesn’t do what I think it would for the (WORK-AROUND) approach

ontology_id = 'XXXXXXXXXXXXXXXXXXX'
existing_ontology = client.get_ontology(ontology_id=ontology_id)

# Create New Ontology (DEFAULT METHOD)
ontology_builder = OntologyBuilder.from_ontology(existing_ontology)
project_ontology_1 = ontology_builder.asdict()

# OR Use Existing Ontology (WORK-AROUND)
ontology_tools = existing_ontology.tools()
ontology_classifications = existing_ontology.classifications()
project_ontology = {
    "tools": [tools.asdict() for tools in ontology_tools],
    "classifications": [classifications.asdict() for classifications in ontology_classifications]
}

# Connect your ontology and editor to your Label Import project
project.setup(editor, project_ontology)
# Connect your dataset to your Label Import project
project.datasets.connect(dataset)

Any help with this would be appreciated.

I think I can go in after and change the Editor ontology in the Project settings to an existing one, explicitly, but this is a manual workaround.

Hi @ceubel, thanks for sharing this post. You are making valid points that address some holes in our documentation which we will address immediately.

If you wish to connect an existing ontology to a project, you can use the following method:

project.setup_editor(ontology)

in which ontology is an object of the ontology class. If you wish to grab the ontology of a specific source project, you can access it with the following snippet:

ontology = source_project.ontology()

or, alternatively, you could grab an ontology by ID using the following:

client.get_ontology(ontology_id)

Hopefully these options provide the functionality you are looking for, and please let me know if you have any additional questions!

1 Like

Thank you @Zeke this worked!