Custom step

Custom steps

It is also possible to write custom steps in Python to implement the steps that are missing to build you specific workflow. To do so, you need to write the code of those custom steps in a separate Python file custom_nodes.py.
For each custom step, you need to create a new class that inherits from the CutomNode class, and implement the __init__ and process methods. You will then be able to add steps with this type in your workflow.yaml file (the name of your class is the type of the step).
Custom step
1
from deepomatic.workflows.nodes import CustomNode
2
3
4
class MyCustomStep(CustomNode):
5
def __init__(self, *args, **kwargs):
6
super().__init__(*args, **kwargs)
7
8
def process(self, context, *custom_step_inputs):
9
### Implements the logic of your custom step
Copied!
Let's look at the following custom step and see how you can add arguments and inputs in the logic you implement.
1
steps:
2
- name:
3
type: MyCustomStep
4
inputs:
5
- image_input
6
- category
7
args:
8
my_first_arg: context_technician
9
my_second_arg: intervention_type
Copied!
You might indeed need to add arguments to your custom step, so that you can use the same custom step and adapt it to a specific usage (the model_id is for instance an argument of the Inference step). To do so, you need to specify those arguments in the signature of the __init__ method. You will also probably want to save those values as attributes to use them in the process method.
1
def __init__(self, *args, my_first_arg, my_second_arg, **kwargs):
2
super().__init__(*args, **kwargs)
3
self._context_technician = my_first_arg
4
self._category = my_second_arg
Copied!
In the same way, your step will use input that might be entries of your workflow or outputs from other steps. You are able to use those inputs in the process method to implement the logic that you need.
1
def process(self, context, image_input, category):
Copied!
Finally, the process method should return either:
  • the list of modified or created regions
  • an empty list is nothing has been created or modified
  • None if you want to stop the execution of the following steps in the corresponding workflow branch
Copy link