Deepomatic Platform
v2.4.2
Search
K

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
from deepomatic.workflows.nodes import CustomNode
class MyCustomStep(CustomNode):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def process(self, context, *custom_step_inputs):
### Implements the logic of your custom step
Let's look at the following custom step and see how you can add arguments and inputs in the logic you implement.
steps:
- name:
type: MyCustomStep
inputs:
- image_input
- category
args:
my_first_arg: context_technician
my_second_arg: intervention_type
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.
def __init__(self, *args, my_first_arg, my_second_arg, **kwargs):
super().__init__(*args, **kwargs)
self._context_technician = my_first_arg
self._category = my_second_arg
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.
def process(self, context, image_input, category):
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