At this time you can only import and export metadata with the Python SDK.
import labelbox client = labelbox.Client() mdo = client.get_data_row_metadata_ontology() # List all available fields mdo.fields # Access a field by name, names are unique tag_schema = mdo.reserved_by_name["tag"] # Enums options can be accessed as such train_schema = mdo.reserved_by_name["split"]["train"] # Custom fields custom_field = mdo.custom_by_name["my-custom-field"]
To upload Metadata you must construct two objects. To upload metadata for a DataRow you construct a
DataRowMetadata object which contains the fields
DataRowMetadataFields to put on the DataRow. To construct a metadata field you must provide the Schema Id for the field and value that will be uploaded. Metadata will overwrite on a per-field basis. All metadata uploads are through a bulk endpoint.
# Get data row dr = next(dataset.export_data_rows()) train_schema = mdo.reserved_by_name["split"]["train"] # Construct an enum field field = DataRowMetadataField( schema_id=train_schema.parent, # specify the schema id value=train_schema.uid, # typed inputs ) # Completed object ready for upload upload = DataRowMetadata( data_row_id=dr.uid, # DataRow Id not ExternalId fields=[field] ) # Provide a list of DataRowMetadata objects to upload mdo.bulk_upsert([upload])
# Construct a string field DataRowMetadataField( schema_id=tag_schema.uid, value="my-message", )
from datetime import datetime # Create a utc timezone datetime object dt = datetime.utcnow() # Construct a datetime field DataRowMetadataField( schema_id=mdo.reserved_by_name["captureDateTime"].uid, value=dt, )
# Construct a number field confidence = 0.4 # Construct a datetime field DataRowMetadataField( schema_id=mdo.custom_by_name["confidence"].uid, # custom field value=confidence, )
Metadata can be used within Catalog and Projects to filter data. You can view Metadata on a DataRow using the detail view for a Data Row.
You can bulk export Metadata by Data Row with the SDK. You can specify multiple Data Row IDs in the array.
# Export metadata from a list of data row ids. metadata = mdo.bulk_export([data_row.uid])
You can delete Metadata for a Data Row through the SDK. To delete Metadata for a Data Row, you must specify the fields you want to delete by Schema Id. The deletion will not fail if the Schema Id is not present on the Data Row.
# Specify the schemas to delete schemas = [tag_schema, ...] # Create a delete object deletes = DeleteDataRowMetadata( data_row_id=md.data_row_id, fields=[s.uid for s in schemas] ) mdo.bulk_delete([deletes]) # pass an array of deletes
Updated about 2 months ago