Labels

Updated 5 days ago by Alex Cota

These are some common use cases people have when working with labels in the Python API.

For the definition of a Label, see Overview & data types.

Before you start

Make sure the client is initialized.

from labelbox import Client
client = Client()

Add labels

Use the create_label method for adding a label within a specified project. Only data_row is required.

project = client.get_project("<project_unique_id>")
data_row = dataset.create_data_row(row_data="http://my_site.com/photos/img_01.jpg")
label = project.create_label(data_row=data_row, label="<label_data_here>")

Export labels

The sample below uses the export_labels method to print a URL to a JSON file containing the labels of a project.

project = client.get_project("<project_unique_id>")
url = project.export_labels()
print(url)

The response will be a URL of the label data file.

'https://storage.googleapis.com/labelbox-exports/cjnywra4rytzd
079735j0hfnt/ck22dy2gmnbw08111o6y2ycs9/export-2019-10-29T22:59
:08.592Z.json
'

Bulk Delete Labels

Use the bulk_delete method for deleting multiple labels at a time. Users usually seek to do this when they realize there was an error in the way that the labels were initially created. This method allows you to remove the existing annotations.

Here are two ways for bulk deleting labels within a specified project.

a. Specify a project and delete use the bulk_delete method to delete all labels from that project.

project = client.get_project("<project_unique_id>")
Label.bulk_delete(project.labels())

b. Do a filtered relationship expansion to specify which labels to delete within a project.

project = client.get_project("<project_unique_id>")
Label.bulk_delete(project.labels(where=Label.name=="x"))

Was this section helpful? Give your feedback below.


How did we do?