CWorkflow#

class ikomia.dataprocess.pydataprocess.CWorkflow#

Workflow management of Computer Vision tasks. Implement features to create, modify and run graph-based pipeline of CWorkflowTask objects or derived. Workflows can be created from scratch by using IkomiaRegistry to instanciate and connect task objects. Workflows can also be loaded from JSON file created with the interactive designer of Ikomia Studio. Derived from CWorkflowTask.

Note

A pure Python derived class is also implemented to add higher level features. See Workflow for more information.

Import

from ikomia.dataprocess import CWorkflow

Methods

__init__(arg1)

__init__( (object)self) -> None :

add_input(self, input)

Add global input to the workflow.

add_task(self, task)

Add new task to the workflow.

clear(self)

Remove all tasks and connections from the workflow.

clear_inputs(self)

Remove all inputs of the workflow.

clear_output_data(self)

Clear output data for all the tasks of the workflow.

connect(self, source, target, source_index, ...)

Connect tasks.

delete_edge(self, id)

Remove the given connection/edge from the workflow.

delete_task(self, id)

Remove the given task from the workflow.

export_graphviz(self, path)

Export the workflow structure as Graphviz .dot file.

get_children(self, id)

Get child task identifiers of the task specified by the given identifier.

get_edge_info(self, id)

Get connection information (edge) from its unique identifier.

get_edge_source(self, id)

Get source/parent task identifier of a given edge.

get_edge_target(self, id)

Get target/child task identifier of a given edge.

get_elapsed_time_to(self, task_id)

Get the workflow running time in milliseconds from the start to the given task.

get_final_tasks(self)

Get all final or leaf tasks of the workflow.

get_in_edges(self, id)

Get input connections (in-edges) of the task specified by the given identifier.

get_last_run_folder(self)

Get the output folder for the last run.

get_out_edges(self, id)

Get output connections (out-edges) of the task specified by the given identifier.

get_parents(self, id)

Get parent task identifiers of the task specified by the given identifier.

get_root_id(self)

Get unique identifier of the root node.

get_root_target_types(self)

Get all input data types of the tasks connected to the root node.

get_task(self, id)

Get the task object from the given ID.

get_task_count(self)

Get the number of tasks in the workflow.

get_task_ids(self)

Get the list of all task identifiers.

get_total_elapsed_time(self)

Get the total workflow running time in milliseconds

load(self, path)

Load a workflow previously saved as JSON file.

remove_input(self, index)

Remove global workflow input at the given index.

run(self)

Launch workflow execution.

save(self, path)

Save the workflow as a JSON file.

set_auto_save(self, enable)

Activate/deactivate auto-save mode.

set_input(self, input, index, new_sequence)

Set workflow input at position index.

set_output_folder(self, path)

Set workflow output folder.

stop(self)

Stop workflow execution.Each CWorkflowTask object or derived must reimplement the stop() function that will be called by the workflow.

update_start_time(self)

Reset the starting point for the computation of the running time.

Attributes

description

Workflow description

keywords

Workflow associated keywords

Details

__init__((object)arg1) None#
__init__( (object)self) -> None :

Default constructor

__init__( (object)self, (str)name) -> None :

Construct a new workflow object with the given name.

Args:

name (str): workflow name

__init__( (object)self, (str)name, (CIkomiaRegistry)registry) -> None :

Construct a new workflow object with the given name and Ikomia registry. You should use this constructor if you intend to instanciate tasks from the Ikomia registry (built-in algorithms and Ikomia HUB).

Args:

name (str): workflow name

registry (IkomiaRegistry): algorithms registry

__init__( (object)arg1, (CWorkflow)arg2) -> None :

Copy constructor

add_input((CWorkflow)self, (CWorkflowTaskIO)input) None :#

Add global input to the workflow.

Parameters:

input (CWorkflowTaskIO based object) – input object

add_task((CWorkflow)self, (CWorkflowTask)task) int :#

Add new task to the workflow.

Parameters:

task (CWorkflowTask or derived) –

clear((CWorkflow)self) None :#

Remove all tasks and connections from the workflow. The workflow is thus empty after that.

clear_inputs((CWorkflow)self) None :#

Remove all inputs of the workflow.

clear_output_data((CWorkflow)self) None :#

Clear output data for all the tasks of the workflow.

connect((CWorkflow)self, (int)source, (int)target, (int)source_index, (int)target_index) None :#

Connect tasks.

Parameters:
  • source (int) – source/parent task identifier

  • target (int) – target/child task identifier

  • source_index (int) – output index of the source task

  • target_index (int) – input index of the target task

delete_edge((CWorkflow)self, (int)id) None :#

Remove the given connection/edge from the workflow. The identifier becomes invalid after this operation.

Parameters:

id (int) – edge identifier

delete_task((CWorkflow)self, (int)id) None :#

Remove the given task from the workflow. The identifier becomes invalid after this operation.

Parameters:

id (int) – task identifier

export_graphviz((CWorkflow)self, (str)path) None :#

Export the workflow structure as Graphviz .dot file. You can then visualize it with the dot command or with Graphviz Python package.

Parameters:

path (str) – path where the .dot file is saved

get_children((CWorkflow)self, (int)id) object :#

Get child task identifiers of the task specified by the given identifier. Task connected to the outputs of a given task is designated as child or target.

Parameters:

id (int) – task identifier on which to get childs

Returns:

child identifiers

Return type:

int list

get_edge_info((CWorkflow)self, (int)id) tuple :#

Get connection information (edge) from its unique identifier.

Parameters:

id (int) – edge identifier

Returns:

pair composed by the output index of the source/parent task and the input index of the target/child task

Return type:

tuple (int)

get_edge_source((CWorkflow)self, (int)id) int :#

Get source/parent task identifier of a given edge.

Parameters:

id (int) – edge identifier

Returns:

task identifier

Return type:

id (int)

get_edge_target((CWorkflow)self, (int)id) int :#

Get target/child task identifier of a given edge.

Parameters:

id (int) – edge identifier

Returns:

task identifier

Return type:

id (int)

get_elapsed_time_to((CWorkflow)self, (int)task_id) float :#

Get the workflow running time in milliseconds from the start to the given task.

Parameters:

id (int) – task identifier

Returns:

elapsed time

Return type:

float

get_final_tasks((CWorkflow)self) object :#

Get all final or leaf tasks of the workflow.

Returns:

leaf task identifiers

Return type:

int list

get_in_edges((CWorkflow)self, (int)id) object :#

Get input connections (in-edges) of the task specified by the given identifier. Edge information can then be retrieved by the function get_edge_info().

Parameters:

id (int) – task identifier

Returns:

edge identifiers

Return type:

int list

get_last_run_folder((CWorkflow)self) str :#

Get the output folder for the last run. Output folder can be set with set_output_folder(). It will be used only if auto-save mode is enabled and a timestamp is automatically added. The complete name is returned by this method.

Returns:

output folder path (with timestamp added)

Return type:

str

get_out_edges((CWorkflow)self, (int)id) object :#

Get output connections (out-edges) of the task specified by the given identifier. Edge information can then be retrieved by the function get_edge_info().

Parameters:

id (int) – task identifier

Returns:

edge identifiers

Return type:

int list

get_parents((CWorkflow)self, (int)id) object :#

Get parent task identifiers of the task specified by the given identifier. Task connected to the inputs of a given task is designated as parent or source.

Parameters:

id (int) – task identifier on which to get parents

Returns:

parent identifiers

Return type:

int list

get_root_id((CWorkflow)self) int :#

Get unique identifier of the root node.

Returns:

root node ID

Return type:

int

get_root_target_types((CWorkflow)self) object :#

Get all input data types of the tasks connected to the root node.

Returns:

data types

Return type:

list of IODataType

get_task((CWorkflow)self, (int)id) CWorkflowTask :#

Get the task object from the given ID. Unique task identifiers can be retrieved with the functions get_task_ids() or find_task().

Returns:

CWorkflowTask object or derived

get_task_count((CWorkflow)self) int :#

Get the number of tasks in the workflow.

Returns:

task count

Return type:

int

get_task_ids((CWorkflow)self) object :#

Get the list of all task identifiers. You can then retrieve task object from ID with the function get_task().

get_total_elapsed_time((CWorkflow)self) float :#

Get the total workflow running time in milliseconds

Returns:

elapsed time

Return type:

float

load((CWorkflow)self, (str)path) None :#

Load a workflow previously saved as JSON file. Common usage is to use Ikomia Studio to create your workflow interactively and without code. With this method, it is very easy and fast to build your pipeline, visualize outputs on test data and save the workflow. But you can also create your workflow from scratch with this API and use the dedicated function save().

Parameters:

path (str) – path of the JSON file

remove_input((CWorkflow)self, (int)index) None :#

Remove global workflow input at the given index.

Parameters:

index (int) – zero-based index of the input to remove

run((CWorkflow)self) None :#

Launch workflow execution. Each CWorkflowTask object or derived must reimplement the run() function that will be called in the right order by the workflow. Please note that global inputs should be set before calling this function.

run( (CWorkflow)self) -> None

save((CWorkflow)self, (str)path) None :#

Save the workflow as a JSON file.

Parameters:

path (str) – path where the JSON is saved

set_auto_save((CWorkflow)self, (bool)enable) None :#

Activate/deactivate auto-save mode. If activated, outputs of each tasks of the workflow will be saved in the workflow output folder (see set_output_folder() to set your custom folder). By default, outputs are saved in user_folder/Ikomia/Workflows.

Parameters:

enable (bool) – True or False

set_input((CWorkflow)self, (CWorkflowTaskIO)input, (int)index, (bool)new_sequence) None :#

Set workflow input at position index. If index is greater than the input count, the function adds the right number of inputs automatically. Derived class that handles common data type already exists: CImageIO, CVideoIO, CNumericIO, CGraphicsInput, CDatasetIO, CPathIO, CArrayIO, CBlobMeasureIO.

Parameters:
  • input (CWorkflowTaskIO object or derived) – global input of the workflow

  • index (int) – zero-based index

  • new_sequence (bool) – True if it is a new input sequence, False if it is just a new frame of a video or camera stream

set_output_folder((CWorkflow)self, (str)path) None :#

Set workflow output folder. If auto-save mode is activated (see set_auto_save()) outputs of each tasks of the workflow will be saved automatically in this folder. Behind the scene, each task implements a save() function that calls sequentially the save() function of all these outputs.

Parameters:

path (str) – path to the desired directory

stop((CWorkflow)self) None :#

Stop workflow execution.Each CWorkflowTask object or derived must reimplement the stop() function that will be called by the workflow. Depending on the process implementation, stop may not be instantaneous.

update_start_time((CWorkflow)self) None :#

Reset the starting point for the computation of the running time. This feature could be interesting if you want to process a list of images and monitor the time per image.