CWorkflowTask

class ikomia.core.pycore.CWorkflowTask

Base class for all tasks that aim to be executed in a workflow. It provides all basic mechanisms to handle inputs and outputs, task parameters and progress feedbacks. It also provides an interface through overridable methods to set a formal scope to design custom tasks. This interface allows the implementation of various image-based processes. One can also use the derived classes of the API which cover basic needs for 2D image, volume (see C2dImageTask), or video (see CVideoTask).

Import

from ikomia.core import CWorkflowTask

Methods

__init__(arg1)

__init__( (object)self) -> None :

add_input(self, input)

Add new input to the task.

add_output(self, output)

Add new output to the task.

begin_task_run(self)

Perform all initialization stuff before running the task.

clear_inputs(self)

Remove all task inputs.

clear_outputs(self)

Remove all task outputs.

download(self, url, to)

Download file from the given URL and save it to the given path.

emit_add_sub_progress_steps(self, count)

Send event to add or remove progress steps to the progress bar.

emit_graphics_context_changed(self)

Send event to notify that graphics context has changed inside the task and display has to be updated.

emit_output_changed(self)

Send event to notify that some outputs have changed and that display must be updated.

emit_step_progress(self)

Send step event to notify progress bar system.

end_task_run(self)

Performs all finalization stuff after running the task.

execute_actions(self, action)

Method called when a specific action is requested from the associated widget (see emit_send_process_action()).

get_elapsed_time(self)

Get the time of the last execution in milliseconds.

get_input(self, index)

Get input at position index.

get_input_count(self)

Get the number of inputs.

get_input_data_type(self, index)

Get input data type at position index.

get_inputs(self)

Get the whole list of inputs.

get_output(self, index)

Get output at position index.

get_output_count(self)

Get the number of outputs.

get_output_data_type(self, index)

Get output data type at position index.

get_outputs(self)

Get the whole list of outputs.

get_param_object(self)

Get task parameters.

get_parameters(self)

Get values of task parameters.

get_progress_steps(self)

Get the number of progress steps when the system runs the task.

global_input_changed(self, is_new_sequence)

Notify that the inputs of the workflow have changed.

graphics_changed(self)

Notify that graphics layers of input images have changed.

is_graphics_changed_listening(self)

Check whether the task is listening to graphics changed event.

parameters_modified(self)

Notify that the task parameters have changed.

remove_input(self, index)

Remove input at the given position.

run(self)

Run the task.

set_action_flag(self, action, is_enable)

Enable or disable the given action.

set_active(self, is_active)

Set the active state of the task.

set_auto_save(self, enable)

Enable/disable auto-save mode.

set_input(self, input, index)

Set input at position index with the given one.

set_input_data_type(self, data_type, index)

Set the data type for the input at position index.

set_inputs(self, inputs)

Set the whole list of inputs with the given one.

set_output(self, output, index)

Set output at position index with the given one.

set_output_data_type(self, data_type, index)

Set the data type for the output at position index.

set_outputs(self, outputs)

Set the whole list of outputs with the given one.

set_param_object(self, param)

Set the task parameters object.

set_parameters(self, values)

Set values of task parameters.

stop(self)

Notify that the task is requested to stop.

update_static_outputs(self)

Updates the static information deduced from inputs.

workflow_started(self)

Notify that the workflow executing the task is started.

workflow_finished(self)

Notify that the workflow executing the task is started.

Attributes

name

Task name (must be unique)

output_folder

Output folder when auto-save mode is enabled.

type

Main purpose or data type on which the task is dedicated to.

Details

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

Default constructor

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

Construct CWorkflowTask object with the given task name.

Args:

name (str): task name, must be unique

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

Copy constructor

add_input((CWorkflowTask)self, (CWorkflowTaskIO)input) None :

Add new input to the task.

Args:

input (CWorkflowTaskIO based object): input object

add_input( (CWorkflowTask)self, (CWorkflowTaskIO)input) -> None

add_output((CWorkflowTask)self, (CWorkflowTaskIO)output) None :

Add new output to the task.

Args:

output (CWorkflowTaskIO based object): output object

add_output( (CWorkflowTask)self, (CWorkflowTaskIO)output) -> None

begin_task_run((CWorkflowTask)self) None :

Perform all initialization stuff before running the task. This method can be overriden to put custom initialization steps. In this case, don’t forget to call the base class method. This method must be the first call of the run() method.

begin_task_run( (CWorkflowTask)self) -> None

clear_inputs((CWorkflowTask)self) None :

Remove all task inputs.

clear_outputs((CWorkflowTask)self) None :

Remove all task outputs.

download((CWorkflowTask)self, (str)url, (str)to) None :

Download file from the given URL and save it to the given path. The method returns only when download is complete.

Parameters:
  • url (string) – url of the file to download

  • to (string) – destination path

emit_add_sub_progress_steps((CWorkflowTask)self, (int)count) None :

Send event to add or remove progress steps to the progress bar.

Parameters:

count (int) – positive value to add steps, negative value to remove steps

emit_graphics_context_changed((CWorkflowTask)self) None :

Send event to notify that graphics context has changed inside the task and display has to be updated.

emit_output_changed((CWorkflowTask)self) None :

Send event to notify that some outputs have changed and that display must be updated.

emit_step_progress((CWorkflowTask)self) None :

Send step event to notify progress bar system.

end_task_run((CWorkflowTask)self) None :

Performs all finalization stuff after running the task. This method can be overriden to put custom finalization steps. In this case, don’t forget to call the base class method. This method must be the last call of the run() method.

end_task_run( (CWorkflowTask)self) -> None

execute_actions((CWorkflowTask)self, (int)action) None :

Method called when a specific action is requested from the associated widget (see emit_send_process_action()).

Args:

action (int): action code

execute_actions( (CWorkflowTask)self, (int)action) -> None

get_elapsed_time((CWorkflowTask)self) float :

Get the time of the last execution in milliseconds.

Returns:

elapsed time in ms

Return type:

float

get_input((CWorkflowTask)self, (int)index) CWorkflowTaskIO :

Get input at position index.

Parameters:

index (int) – zero-based input index

Returns:

input object

Return type:

CWorkflowTaskIO based object

get_input_count((CWorkflowTask)self) int :

Get the number of inputs.

Returns:

inputs count

Return type:

int

get_input_data_type((CWorkflowTask)self, (int)index) IODataType :

Get input data type at position index. This data type can differ from the original type because it can change at runtime according to the data source.

Parameters:

index (int) – zero-based input index

Returns:

input data type

Return type:

IODataType

get_inputs((CWorkflowTask)self) object :

Get the whole list of inputs.

Returns:

input objects

Return type:

list of CWorkflowTaskIO based objects

get_output((CWorkflowTask)self, (int)index) CWorkflowTaskIO :

Get output at position index.

Parameters:

index (int) – zero-based output index

Returns:

output object

Return type:

CWorkflowTaskIO based object

get_output_count((CWorkflowTask)self) int :

Get the number of outputs.

Returns:

outputs count

Return type:

int

get_output_data_type((CWorkflowTask)self, (int)index) IODataType :

Get output data type at position index. This data type can differ from the original type because it can change at runtime according to the data source.

Parameters:

index (int) – zero-based output index

Returns:

output data type

Return type:

IODataType

get_outputs((CWorkflowTask)self) object :

Get the whole list of outputs.

Returns:

output objects

Return type:

list of CWorkflowTaskIO based objects

get_param_object((CWorkflowTask)self) CWorkflowTaskParam :

Get task parameters.

Returns:

parameter object

Return type:

CWorkflowTaskParam based object

get_parameters((CWorkflowTask)self) object :

Get values of task parameters.

Returns:

string pairs (parameter name, value)

Return type:

dict

get_progress_steps((CWorkflowTask)self) int :

Get the number of progress steps when the system runs the task.

Returns:

int: steps count

get_progress_steps( (CWorkflowTask)self) -> int

global_input_changed((CWorkflowTask)self, (bool)is_new_sequence) None :

Notify that the inputs of the workflow have changed. This method can be overriden to implement custom actions when this event happens. The method does nothing in this base class.

Args:

is_new_sequence (bool): True if new input is a new sequence (ex: new frame of the same video is not a new sequence)

global_input_changed( (CWorkflowTask)self, (bool)is_new_sequence) -> None

graphics_changed((CWorkflowTask)self) None :

Notify that graphics layers of input images have changed. This method can be overriden to implement custom actions when this event happens. The method does nothing in this base class.

graphics_changed( (CWorkflowTask)self) -> None

is_graphics_changed_listening((CWorkflowTask)self) bool :

Check whether the task is listening to graphics changed event.

Returns:

bool: True or False

is_graphics_changed_listening( (CWorkflowTask)self) -> bool

parameters_modified((CWorkflowTask)self) None :

Notify that the task parameters have changed. This method can be overriden to implement custom actions when this event happens. The method does nothing in this base class.

parameters_modified( (CWorkflowTask)self) -> None

remove_input((CWorkflowTask)self, (int)index) None :

Remove input at the given position.

Parameters:

index (int) – zero-based input index

run((CWorkflowTask)self) None :

Run the task. It’s where the main process of the task has to be implemented. In this base class, the method just forwards the inputs to outputs. It has to be overriden in derived class.

run( (CWorkflowTask)self) -> None

set_action_flag((CWorkflowTask)self, (ActionFlag)action, (bool)is_enable) None :

Enable or disable the given action. If the action does not exist, it is added to the list.

Parameters:
  • action (ActionFlag) – action to enable or disable

  • is_enable (bool) – True or False

set_active((CWorkflowTask)self, (bool)is_active) None :

Set the active state of the task. The active task is the one selected in the workflow, thus, user has access to parameters and can visualize results associated with the task.

Args:

is_active (bool): True or False

set_active( (CWorkflowTask)self, (bool)is_active) -> None

set_auto_save((CWorkflowTask)self, (bool)enable) None :

Enable/disable auto-save mode. When this mode is enabled, task outputs are automatically save to disk when the run() function is executed. Save formats are already defined for all builtin I/O objects. For custom I/O object, one must implement load() and save() methods. Output folder can be set with output_folder.

Parameters:

enable (bool) – True to enable, False to disable

set_input((CWorkflowTask)self, (CWorkflowTaskIO)input, (int)index) None :

Set input at position index with the given one. If the input at position index does not exist, the function creates as many generic inputs to reach the number of index+1 and sets the input at position index.

Args:

input_tot (CWorkflowTaskIO based object)

index (int): zero-based input index

set_input( (CWorkflowTask)self, (CWorkflowTaskIO)input, (int)index) -> None

set_input_data_type((CWorkflowTask)self, (IODataType)data_type, (int)index) None :

Set the data type for the input at position index. If the input at position index does not exist, the function creates as many generic inputs to reach the number of index+1 and sets the data type for the input at position index.

Args:

data_type (IODataType): input data type

index (int): zero-based input index

set_input_data_type( (CWorkflowTask)self, (IODataType)data_type, (int)index) -> None

set_inputs((CWorkflowTask)self, (object)inputs) None :

Set the whole list of inputs with the given one.

Args:

inputs (list of CWorkflowTaskIO based objects)

set_inputs( (CWorkflowTask)self, (object)inputs) -> None

set_output((CWorkflowTask)self, (CWorkflowTaskIO)output, (int)index) None :

Set output at position index with the given one. If the output at position index does not exist, the function creates as many generic outputs to reach the number of index+1 and sets the output at position index.

Args:

output (CWorkflowTaskIO based object)

index (int): zero-based output index

set_output( (CWorkflowTask)self, (CWorkflowTaskIO)output, (int)index) -> None

set_output_data_type((CWorkflowTask)self, (IODataType)data_type, (int)index) None :

Set the data type for the output at position index. If the output at position index does not exist, the function creates as many generic outputs to reach the number of index+1 and sets the data type for the output at position index.

Args:

data_type (IODataType): output data type

index (int): zero-based output index

set_output_data_type( (CWorkflowTask)self, (IODataType)data_type, (int)index) -> None

set_outputs((CWorkflowTask)self, (object)outputs) None :

Set the whole list of outputs with the given one.

Args:

outputs (list of CWorkflowTaskIO based objects)

set_outputs( (CWorkflowTask)self, (object)outputs) -> None

set_param_object((CWorkflowTask)self, (CWorkflowTaskParam)param) None :

Set the task parameters object. Task can have only one parameters object.

Parameters:

paramCWorkflowTaskParam based object

set_parameters((CWorkflowTask)self, (object)values) None :

Set values of task parameters.

Parameters:

values (dict) – string pairs (parameter name, value)

stop((CWorkflowTask)self) None :

Notify that the task is requested to stop. It is higly recommended to manage this stop event and override the method for time-consuming tasks. Base class implementation must be called before any other instructions.

stop( (CWorkflowTask)self) -> None

update_static_outputs((CWorkflowTask)self) None :

Updates the static information deduced from inputs. The static data corresponds to all data that can be deduced without the runtime context. This method is called each time inputs change.

update_static_outputs( (CWorkflowTask)self) -> None

workflow_started((CWorkflowTask)self) None :

Notify that the workflow executing the task is started. The function is called before the run() function of each task.The function can be overriden in child classes to manage custom actions.

workflow_started( (CWorkflowTask)self) -> None

workflow_finished((CWorkflowTask)self) None :

Notify that the workflow executing the task is started. The function is called before the run() function of each task.The function can be overriden in child classes to manage custom actions.

workflow_finished( (CWorkflowTask)self) -> None