Workflows are a powerful tool to design and build your Projects - letting you control how an annotation task moves through different stages of the Project, and determining how different stages are structured and interact with one another.
Creating a Workflow Project
To create a Workflow Project using the SDK:
- First create a Workflow template in the Encord platform.
- Then use the Workflow template ID, highlighted in the screenshot below, as a parameters to the create_project() method.
To use an existing template when creating a Project, users must have Admin privileges on the template. We recommend creating a copy of the Workflow template before Project creation, to ensure you have Admin privileges.
Projects cannot be deleted using the SDK or the API. Use the Encord platform to delete Projects.
Moving tasks between Workflow stages
Moving tasks to the first Workflow stage
Use the workflow_reopen() method to reopen tasks. Reopening tasks moves tasks back to the first stage in your Workflow.
This example returns all tasks in the Project:
from encord.user_client import EncordUserClient
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
project = user_client.get_project(
"<project-hash>"
)
for label_row in project.list_label_rows_v2():
label_row.workflow_reopen()
The example returns all tasks in a Project back to the first Workflow stage. To reopen individual tasks, modify the final lines to specify the label row you want to reopen.
label_row[0].workflow_reopen()
We recommend using Bundles when reopening many tasks. Bundles improve performance by reducing the number of networks calls to Encord’s servers.
from encord.user_client import EncordUserClient
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
project = user_client.get_project(
"<project-hash>"
)
with project.create_bundle() as bundle:
for label_row in project.list_label_rows_v2():
label_row.workflow_reopen(bundle=bundle)
Moving tasks to the Complete stage
workflow_complete() moves Workflow tasks to the Complete stage.
When moving with many label rows at the same time, create a Bundle. Bundles improve performance by reducing the number of networks calls to Encord’s servers.
In Consensus Projects, tasks in the COMPLETE and ARCHIVE blocks CANNOT be reopened.
from encord.user_client import EncordUserClient
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
project = user_client.get_project(
"<project-hash>"
)
with project.create_bundle() as bundle:
for label_row in project.list_label_rows_v2():
label_row.workflow_complete(bundle=bundle)
Referencing tasks in specific Workflow stages
The workflow_graph_node()
method returns the location of a task within the workflow in the form of a uuid
and a title
. The title
corresponds to the name of the current stage in the Workflow.
The workflow_complete()
method moves a task to the final Workflow stage marking it as Complete.
The following example shows how the workflow_graph_node()
method and the workflow_complete()
method can be used together to move all tasks in a specified Workflow stage to Complete.
from encord.user_client import EncordUserClient
user_client = EncordUserClient.create_with_ssh_private_key(ssh_private_key_path='\<private_key_path>')
project = user_client.get_project(
"<project-hash>"
)
for label_row in project.list_label_rows_v2():
if label_row.workflow_graph_node.title == "<review_stage_2>":
label_row.workflow_complete()
Priorities
You can read and assign task priorities using the SDK. Priorities in the SDK are represented by numbers ranging from 0 to 1, where 1 corresponds to 100
in the Encord platform, the highest priority value.
The following example reads the priority of the first label row, and then changes it to 0.9
.
from encord.user_client import EncordUserClient
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
project = user_client.get_project(
"<project-hash>"
)
label_row = project.list_label_rows_v2()[0]
label_row.initialise_labels()
print(f"Current priority: {label_row.priority}")
label_row.set_priority(0.2)
label_row = project.list_label_rows_v2()[0]
print(f"New priority: {label_row.priority}")
"Current priority: 0.5"
"New priority: 0.2"
To change the priority of multiple label rows at the same time, create a Bundle. Bundles improve performance by reducing the number of networks calls to Encord’s servers.
You cannot set the priority for more than 100 tasks in a bundle.
from encord.user_client import EncordUserClient
user_client = EncordUserClient.create_with_ssh_private_key(
ssh_private_key_path="<private_key_path>"
)
project = user_client.get_project(
"<project-hash>"
)
with project.create_bundle() as bundle:
for label_row in project.list_label_rows_v2():
label_row.set_priority(0.5, bundle=bundle)