Filter Presets

Filter presets are saved groups of filter criteria that you can reuse across Active.

Create Filter Preset

Create a Filter Preset based on raw JSON.

For more information on creating your own filter presets using the SDK, contact us at support@encord.com

# Import dependencies
from encord import EncordUserClient

from encord.orm.filter_preset import FilterPresetDefinition, FilterDefinition
from encord.orm.filter_preset import FilterPreset as OrmFilterPreset

SSH_PATH = "<file-path-to-ssh-key>"
PROJECT_ID = "<project-unique-id>"

# Initialize the user client
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Get project
project = user_client.get_project(PROJECT_ID)


# Define the filter preset structure

# Create a preset with the defined filter preset
preset = project.create_filter_preset(
    name="<name-for-your-preset>",
    filter_preset= FilterPresetDefinition(global_filters=FilterDefinition(
        filters= [{'key':'<key-name>',
        'include':True or False,
        'values' : [<fitler-values>],
        'type': '<client-metadata-type'}]
    )
 ))

# Output the result
print(f"Preset created with UUID: {preset.uuid}")
print("Preset contents: ", preset.get_filter_preset_json())

Update Filter Presets

All arguments are optional when updating a filter preset.

# Import dependencies
from encord import EncordUserClient

from encord.orm.filter_preset import FilterPresetDefinition, FilterDefinition
from encord.orm.filter_preset import FilterPreset as OrmFilterPreset

SSH_PATH = "<file-path-to-ssh-key>"
PROJECT_ID = "<project-unique-id>"
PRESET_ID = "<preset-unique-id>"

# Initialize the user client
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Get project
project = user_client.get_project(PROJECT_ID)

# Create a preset with the defined filter preset
preset = project.get_filter_preset(filter_preset_uuid=PRESET_ID)
preset.update_preset(
    name="<updated-preset-name>",
    filter_preset= FilterPresetDefinition(global_filters=FilterDefinition(
        filters= [{'key':'<key-name>',
        'include':True or False,
        'values' : [<fitler-values>],
        'type': '<client-metadata-type>'}]
    )
  )
 )

# Output the result
print(f"Updated Preset with UUID: {preset.uuid}")


List Filter Presets

List all Filter Presets in Active by name with their unique identifier.


# Import dependencies
from encord import EncordUserClient

SSH_PATH = "file-path-to-ssh-private-key"
PROJECT_ID = "<project_hash>"

user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Get project
project = user_client.get_project(PROJECT_ID)

# Get Preset Filters for the project
presets = project.list_filter_presets()

# List Preset Filters by name and UUID
for preset in presets:
    print(preset.name, preset.uuid)

Delete Presets

Use the following code template to delete a preset filter in Active.

Template

# Import dependencies
from encord import EncordUserClient

SSH_PATH = "file-path-to-ssh-private-key"
PROJECT_ID = "<project-unique-id>"

# Preset ID to delete
PRESET_ID = "unique-preset-filter-id"  

user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Get project
project = user_client.get_project(PROJECT_ID)

# Delete Preset Filter
project.delete_filter_preset(PRESET_ID)

View Preset JSON

This code outputs the filters that make up the Active filter preset in a JSON file format.

# Import dependencies
from encord import EncordUserClient

from encord.orm.filter_preset import FilterPreset as OrmFilterPreset

SSH_PATH = "<file-path-to-ssh-private-key>"
PROJECT_ID = "<project-unique-id>"
PRESET_ID = "<uuid-of-the-preset-filter>"

user_client: EncordUserClient = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Get project
project = user_client.get_project(PROJECT_ID)

# Get filter preset and return the JSON representation
filter_preset_json = project.get_filter_preset(filter_preset_uuid=PRESET_ID).get_filter_preset_json()

# Output the result
print("\nFormatted Output:\n")
print(filter_preset_json)


Collections

Active supports two types of Collections: Frame Collections and Label Collections.

Frame Collections are groups of frames (images and video frames) you selected by filtering, sorting, inspecting, and analyzing the data units in Active.

Label Collections are groups of labels, on your frames (images and video frames), that you selected by filtering, sorting, inspecting, and analyzing the labels on your data units in Active.

List Collections

List all Collections in an Active Project by name with their unique identifier.


from encord import EncordUserClient
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest, ProjectCollectionBulkItemResponse

SSH_PATH = "<file-path-to-ssh-private-key>"

PROJECT_ID = "<unique-annotate-project-id>"

user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

project = user_client.get_project(PROJECT_ID)

print(project.title)

collections = project.list_collections()
for collection in collections:
    print(collection.name, collection.collection_type, collection.uuid)

List FRAME Collections

List all FRAME Collections in an Active Project by name with their unique identifier.


from encord import EncordUserClient
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest, ProjectCollectionBulkItemResponse

SSH_PATH = "<file-path-to-ssh-private-key>"

PROJECT_ID = "<unique-annotate-project-id>"

user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

project = user_client.get_project(PROJECT_ID)

print(project.title)

collections = project.list_collections()

for collection in collections:
    # Check if the collection type is 'FRAME'
    if collection.collection_type == ProjectCollectionType.FRAME:
        print(collection.name, collection.collection_type, collection.uuid)

List LABEL Collections

List all LABEL Collections in an Active Project by name with their unique identifier.


from encord import EncordUserClient
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest, ProjectCollectionBulkItemResponse

SSH_PATH = "<file-path-to-ssh-private-key>"

PROJECT_ID = "<unique-annotate-project-id>"

user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

pproject = user_client.get_project(PROJECT_ID)

print(project.title)

collections = project.list_collections()

# Specify LABEL Collections
if collection.collection_type == ProjectCollectionType.LABEL:
        print(collection.name, collection.collection_type, collection.uuid)

Create Collection

Create a Collection with a meaningful name and description in a Folder.

from encord import EncordUserClient
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest

SSH_PATH = "<file-path-to-ssh-private-key>"

PROJECT_ID = "<unique-annotate-project-id>"

user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

project = user_client.get_project(PROJECT_ID)

collection = project.create_collection(name="Test Collection 1", description="A useful and meaningful description for the Collection.", collection_type= "<FRAME-or-LABEL>")

print(collection)

Add Items to a Collection

You need the data hash of the data units in your Annotate Project to add the data units to an Active Collection.

Add Items to a Collection using Presets

The code to add items to a Frame Collection or a Label Collection is the same.

You can find the Preset ID for your preset in the Active UI.


# Import dependencies
from encord import EncordUserClient
from encord.collection import ProjectCollection
from encord.orm.filter_preset import FilterPreset
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest


# Define constants
SSH_PATH = "<file-path-to-ssh-private-key>"

PROJECT_ID = "<project-unique-id>"

COLLECTION_ID = "<collection-unique-id>"

PRESET_ID = "<preset-unique-id>"

# Initialize the user client using the SSH private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Fetch the specific Project by ID
project = user_client.get_project(PROJECT_ID)


# Fetch the specific Collection by ID
collection = project.get_collection(COLLECTION_ID)


collection.add_preset_items(PRESET_ID)

print(f"Added items to collection {COLLECTION_ID}.")


Remove Items from a Collection

Remove items from a Frame or Label Collection.

Remove Items From a Collection using Presets

The code to remove items from a Frame Collection or a Label Collection is the same.

You can find the Preset ID for your preset in the Active UI.


# Import dependencies
from encord import EncordUserClient
from encord.collection import ProjectCollection
from encord.orm.filter_preset import FilterPreset
from encord.objects.coordinates import BoundingBoxCoordinates
from encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest


# Define constants
SSH_PATH = "<file-path-to-ssh-private-key>"

PROJECT_ID = "<project-unique-id>"

COLLECTION_ID = "<collection-unique-id>"

PRESET_ID = "<preset-unique-id>"

# Initialize the user client using the SSH private key
user_client = EncordUserClient.create_with_ssh_private_key(
    ssh_private_key_path=SSH_PATH
)

# Fetch the specific Project by ID
project = user_client.get_project(PROJECT_ID)


# Fetch the specific Collection by ID
collection = project.get_collection(COLLECTION_ID)


collection.remove_preset_items(PRESET_ID)

print(f"Removed items from Collection {COLLECTION_ID}.")


List all Items in a Collection