List all Filter Presets in Active by name with their unique identifier.
Copy
# Import dependenciesfrom encord import EncordUserClientSSH_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 projectproject = user_client.get_project(PROJECT_ID)# Get Preset Filters for the projectpresets = project.list_filter_presets()# List Preset Filters by name and UUIDfor preset in presets: print(preset.name, preset.uuid)
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.
Use the following code to get the Data ID (unique ID for data units from Dataset) from your Annotate Project:
Copy
# Import dependenciesfrom encord import EncordUserClientSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Specify Project. Replace <project_hash> with the hash of your Project.project = user_client.get_project(PROJECT_ID)# Get label rows for your Projectlabel_rows = project.list_label_rows_v2()# Iterate through label rows and print data hashes and titlesfor label_row in label_rows: print(f"Data hash: {label_row.data_hash}") print(f"Data title: {label_row.data_title}") print("---") # Separator for readability
You need the Data ID, frame number, AND the Annotation ID (Object Hash) for the label or classification you want to add to the LABEL Collection.
The following code gets the Annotation ID for all the labels in an Annotate Project
Copy
# Import dependenciesfrom encord import EncordUserClientSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Specify Project. Replace <project_hash> with the hash of your Project.project = user_client.get_project(PROJECT_ID)# Get label rows for your Projectlabel_rows = project.list_label_rows_v2()# Iterate through label rows and print data hashes, titles, and label hashesfor label_row in label_rows: print(f"Data hash: {label_row.data_hash}") print(f"Data title: {label_row.data_title}") print(f"Label hash: {label_row.data_hash}") print("---") # Separator for readability
You need the Data ID and frame number of the frames you want to add to a Collection.
Copy
# Import dependenciesfrom encord import EncordUserClientfrom encord.collection import ProjectCollectionfrom encord.orm.filter_preset import FilterPresetfrom encord.objects.coordinates import BoundingBoxCoordinatesfrom encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest# Define constantsSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"COLLECTION_ID = "<collection-unique-id>"# Initialize the user client using the SSH private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Fetch the specific Project by IDproject = user_client.get_project(PROJECT_ID)# Fetch the specific collection by hashcollection = project.get_collection(COLLECTION_ID)# Add items to the collection and capture the responseresponse = collection.add_items([ProjectDataCollectionItemRequest(data_uuid="<data-unique-id>", frame=<frame-number>)])# Print the success messageprint(f"Added items to collection {COLLECTION_ID}.")# Check if there were any failed itemsif isinstance(response, ProjectCollectionBulkItemResponse): failed_items = response.failed_items if failed_items: print("The following items failed to be added to the collection:") for failed_item in failed_items: # Assuming failed_item is an instance of either ProjectDataCollectionItemRequest or ProjectLabelCollectionItemRequest print(f"Failed item: {failed_item}") else: print("All items were added successfully.")else: print("Unexpected response format.")
You need the Data ID, frame number, AND the Annotation ID to add items to a LABEL Collection.
Copy
# Import dependenciesfrom encord import EncordUserClientfrom encord.collection import ProjectCollectionfrom encord.orm.filter_preset import FilterPresetfrom encord.objects.coordinates import BoundingBoxCoordinatesfrom encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest# Define constantsSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"COLLECTION_ID = "<collection-unique-id>"# Initialize the user client using the SSH private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Fetch the specified Project by IDproject = user_client.get_project(PROJECT_ID)# Fetch the specific Collection by IDcollection = project.get_collection(COLLECTION_ID)# Add items to the collection and capture the responseresponse = collection.add_items([ProjectLabelCollectionItemRequest(data_uuid="<data-unique-id>", frame=<frame-number>, annotation_id="<annotation-unique-id>")])# Print the success messageprint(f"Added items to collection {COLLECTION_ID}.")# Check if there were any failed itemsif isinstance(response, ProjectCollectionBulkItemResponse): failed_items = response.failed_items if failed_items: print("The following items failed to be added to the collection:") for failed_item in failed_items: # Assuming failed_item is an instance of ProjectLabelCollectionItemRequest print(f"Failed item: {failed_item}") else: print("All items were added successfully.")else: print("Unexpected response format.")
Use the following code to get the Data ID (unique ID for data units from Dataset) from your Annotate Project:
Copy
# Import dependenciesfrom encord import EncordUserClientSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Specify Project. Replace <project_hash> with the hash of your Project.project = user_client.get_project(PROJECT_ID)# Get label rows for your Projectlabel_rows = project.list_label_rows_v2()# Iterate through label rows and print data hashes and titlesfor label_row in label_rows: print(f"Data hash: {label_row.data_hash}") print(f"Data title: {label_row.data_title}") print("---") # Separator for readability
You need the Data ID AND the Annotation ID (Object Hash) for the label or classification you want to remove from the LABEL Collection.
The following code gets the Annotation ID for all the labels in an Annotate Project
Copy
# Import dependenciesfrom encord import EncordUserClientSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"user_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Specify Project. Replace <project_hash> with the hash of your Project.project = user_client.get_project(PROJECT_ID)# Get label rows for your Projectlabel_rows = project.list_label_rows_v2()# Iterate through label rows and print data hashes and titlesfor label_row in label_rows: print(f"Data hash: {label_row.data_hash}") print(f"Data title: {label_row.data_title}") print("---") # Separator for readability
You need the Data ID of frames to remove items from a FRAME Collection.
Copy
# Import dependenciesfrom encord import EncordUserClientfrom encord.collection import ProjectCollectionfrom encord.orm.filter_preset import FilterPresetfrom encord.objects.coordinates import BoundingBoxCoordinatesfrom encord.orm.collection import ProjectCollectionType, ProjectDataCollectionItemRequest, ProjectLabelCollectionItemRequest# Define constantsSSH_PATH = "<file-path-to-ssh-private-key>"PROJECT_ID = "<project-unique-id>"COLLECTION_ID = "<collection-unique-id>"# Initialize the user client using the SSH private keyuser_client = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path=SSH_PATH)# Fetch the specific Project by IDproject = user_client.get_project(PROJECT_ID)# Fetch the specific Collection by IDcollection = project.get_collection(COLLECTION_ID)# Add images or video frames to a FRAMES Collectioncollection.remove_items([ProjectDataCollectionItemRequest(data_uuid="<data-unique-id>", frame=0)])print(f"Removed items to collection {COLLECTION_ID}.")