Exporting a model

I’m a beginner to labelbox (and also relatively new to using python…). I have a labelled data set in labelbox, and I would like to use the labelled data set to train a model to label input images (and then export this model for use in python). I apologise for the long question but what are the steps for me to do so? Any help would be appreciated! Thanks!

Hey @jschull,

Given you have labeled data, you just need to create a model, a model run (iteration) and allocate the linked ontology, data rows (asset) and then labels.

import labelbox as lb

API_KEY = "<API_KEY>"
client = lb.Client(api_key=API_KEY)

#retrieve the ontology you need to link 
ontology = client.get_ontology("<ONTOLOGY_UID>")

# create Model (name has to be unique)
model = client.create_model(name="My_first_Labelbox_Model", ontology_id=ontology.uid)

# create Model Run (has to be unique)
model_run = model.create_model_run("iteration 1")

#link the data rows, here I will source them from a project
project = client.get_project("<PROJECT_UID>")

#retrieve the data rows from a your project
data_rows = [dr for b in project.batches() for dr in b.export_data_rows()]

#allocate the data rows to your model run
allocate_data_rows = model_run.upsert_data_rows(data_rows)

#add the label to your model run
model_label_import = model_run.upsert_labels(project_id="<PROJECT_UID>")

#Your model prediction
(...)

#import your prediction to your model run (name has to be unique per import)

upload_job_prediction = model_run.add_predictions(
    name="My_first_prediction_import",
    predictions=predictions,
)

Note:

Finally I encourage you to use our documentation for further details : https://docs.labelbox.com/
Our SDK documentation can be found here : Labelbox Python API reference — Python SDK reference 3.49.1 documentation