Custom Metadata in Active

Aligned Image with Page Break

Active supports filtering, creating Collections, and by extension, creating Datasets and Projects based on the custom metadata on your data.

Prereqs

Before you can filter your data or create a Collection based on your data's custom metadata, the custom metadata must exist in your Annotate Project.

ℹ️

Note

This content applies to custom metadata (clientMetadata), which is the metadata associated with individual data units. This is distinct from videoMetadata that is used to specify video parameters when using Strict client-only access. It is also distinct from patient metadata in DICOM files.

Custom metadata (clientMetadata) is accessed by specifying the dataset using the <dataset_hash>. All Projects that have the specified Dataset attached contain custom metadata.

List custom metadata

The following code lists the custom metadata of all data units in the specified Dataset. The code prints the custom metadata along with the data unit's index within the dataset.


# Import dependencies
from encord import EncordUserClient
from encord.client import DatasetAccessSettings

# Authenticate with Encord using the path to your private key
client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
)

# Specify a dataset to read or write metadata to
dataset = client.get_dataset("<dataset_hash>")

# Fetch the dataset's metadata
dataset.set_access_settings(DatasetAccessSettings(fetch_client_metadata=True))

# Read the metadata of all data units in the dataset.
for data_unit, data_row in enumerate(dataset.data_rows):
    print(f"{data_row.client_metadata} - Data Unit: {data_unit}")

Add custom metadata

Add custom metadata to a specific data unit in your Annotate Project

You can add custom metadata (clientMetadata) to specific data units in the dataset.

👍

Tip

You can find the <data unit number> by listing all metadata in the dataset. The sample code provided prints all <data unit number>s.


# Import dependencies
from encord import EncordUserClient
from encord.client import DatasetAccessSettings

# Authenticate with Encord using the path to your private key
client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
)

# Specify a dataset to read or write metadata to
dataset = client.get_dataset("<dataset_hash>")

# Fetch the dataset's metadata
dataset.set_access_settings(DatasetAccessSettings(fetch_client_metadata=True))

# Add metadata to a specific data unit by replacing <data unit number> with the number of the data unit
data_row = dataset.data_rows[<data unit number>]

# Replace {"my": "metadata"} with the metadata you want to add
data_row.client_metadata= {"my": "metadata"}
data_row.save()
print(data_row.client_metadata)

Add custom metadata (clientMetadata) to all data units in a Dataset

The following code adds the same custom metadata (clientMetadata) to each data unit in the specified dataset. The code prints the custom metadata along with the data units index within the dataset, so that you can verify that the custom metadata was set correctly.


# Import dependencies
from encord import EncordUserClient
from encord.client import DatasetAccessSettings

# Authenticate with Encord using the path to your private key
client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path="<private_key_path>"
)

# Specify a dataset to read or write metadata to
dataset = client.get_dataset("<dataset_hash>")

# Fetch the dataset's metadata
dataset.set_access_settings(DatasetAccessSettings(fetch_client_metadata=True))

# Add metadata to all data units in the dataset.
# Replace {"my": "metadata"} with the metadata you want to add
for data_unit, data_row in enumerate(dataset.data_rows):
    data_row.client_metadata = {"my": "metadata"}
    data_row.save()
    print(f"{data_row.client_metadata} - Data Unit: {data_unit}")

Custom Metadata in Active

Once your custom metadata is included in your Annotate Project, you can create Collections based on your custom metadata and then send those Collections to Annotate.

  1. Import your Project that has custom metadata.

  2. Click the Project once import completes.
    The Project opens with the Explorer page displaying.

  3. Filter the Project Data, Labels, or Predictions in the Explorer using a Custom Metadata filter.

    Filter on Custom Metadata

  4. Continue searching, sorting, and filtering your data/labels/predictions until you have the subset of the data you need.

  5. Select one or more of the images in the Explorer workspace.
    A ribbon appears at the top of the Explorer workspace.

  6. Click Select all to select all the images.

  7. Click Add to a Collection.

  8. Click New Collection.

  9. Specify a meaningful title and description for the Collection.

    ℹ️

    Note

    The title specified here is applied as a tag/label to every selected image.

  10. Send the Collection to Annotate.


What’s Next