Common SDK methods

Cheatsheet for most common SDK methods for ontology management

Create new features and ontologies

When you are creating or importing features or ontologies for the first time, use the methods below. Read Annotations reference for a complete list of supported feature types, or simply create a feature in the Schema tab and view its JSON.

from labelbox import OntologyBuilder, Tool, Classification, Option, Client

client = Client()

object_features = [
    Tool(
        tool=Tool.Type.BBOX,
        name="regulatory-sign",
        color="#ff0000",
        classifications=[
            Classification(
                class_type=Classification.Type.RADIO,
                instructions="Sign type",
                options=[
                    Option(value="pedestrian", label="Pedestrian"),
                    Option(value="one_way", label="One way")
                ]
            )
        ]
    )
]

classification_features = [
    Classification(
        class_type=Classification.Type.CHECKLIST,
        instructions="Quality Issues",
        options=[
            Option(value="blurry", label="Blurry"),
            Option(value="distorted", label="Distorted")
        ]
    )

]

ontology_builder = OntologyBuilder(
    tools=object_features,
    classifications=classification_features
)

ontology = client.create_ontology("SDK Demo", ontology_builder.asdict())

Create ontology from existing features

## Search feature by name in your org
regulatory_sign_feature_schema = next(client.get_feature_schemas("regulatory-sign"))
classification_feature = next(client.get_feature_schemas("Quality Issues"))

## Get feature by feature schema ID. You can get this from the UI
regulatory_sign_feature_schema = client.get_feature_schema("FEATURE_SCHEMA_ID")

print(regulatory_sign_feature_schema)
print(classification_feature)

ontology = client.create_ontology_from_feature_schemas("Ontology of shared features", [regulatory_sign_feature_schema.uid, classification_feature.uid])

Read features and ontology

It is best to reuse features and ontologies whenever you can to avoid cluttering your workspace.

#### Fetch by ID
feature_schema = client.get_feature_schema(feature_schema_cat.uid)
ontology = client.get_ontology(ontology.uid)
print(feature_schema)
print(ontology)

### Attach existing ontology with a project
editor = next(client.get_labeling_frontends(where = LabelingFrontend.name == 'editor'))
project.setup(editor, ontology.normalized)

#### Search by name
feature_schema = next(client.get_feature_schemas("cat"))
ontology = next(client.get_ontologies(ontology_name))
print(feature_schema)
print(ontology)

Complete tutorial in Python SDK

Python Tutorial

Github

Google Colab

Working with features and ontologies

Open In GithubOpen In Github

Open In ColabOpen In Colab

Importing Data Row metadata

Open In GithubOpen In Github

Open In ColabOpen In Colab


Did this page help you?