Skip to content

Example Workflows - Workflows with flow control

Below you can find example workflows you can use as inspiration to build your apps.

Workflow with if statement applied on nested batches

In this test scenario we verify if we can successfully apply conditional branching when data dimensionality increases. We first make detections on input images and perform crop increasing dimensionality to 2. Then we make another detections on cropped images and check if inside crop we only see one instance of class dog (very naive way of making sure that bboxes contain only single objects). Only if that condition is true, we run classification model - to classify dog breed.

Workflow definition
{
    "version": "1.0",
    "inputs": [
        {
            "type": "WorkflowImage",
            "name": "image"
        }
    ],
    "steps": [
        {
            "type": "ObjectDetectionModel",
            "name": "first_detection",
            "image": "$inputs.image",
            "model_id": "yolov8n-640"
        },
        {
            "type": "DetectionsTransformation",
            "name": "enlarging_boxes",
            "predictions": "$steps.first_detection.predictions",
            "operations": [
                {
                    "type": "DetectionsOffset",
                    "offset_x": 50,
                    "offset_y": 50
                }
            ]
        },
        {
            "type": "Crop",
            "name": "first_crop",
            "image": "$inputs.image",
            "predictions": "$steps.enlarging_boxes.predictions"
        },
        {
            "type": "ObjectDetectionModel",
            "name": "second_detection",
            "image": "$steps.first_crop.crops",
            "model_id": "yolov8n-640",
            "class_filter": [
                "dog"
            ]
        },
        {
            "type": "ContinueIf",
            "name": "continue_if",
            "condition_statement": {
                "type": "StatementGroup",
                "statements": [
                    {
                        "type": "BinaryStatement",
                        "left_operand": {
                            "type": "DynamicOperand",
                            "operand_name": "prediction",
                            "operations": [
                                {
                                    "type": "SequenceLength"
                                }
                            ]
                        },
                        "comparator": {
                            "type": "(Number) =="
                        },
                        "right_operand": {
                            "type": "StaticOperand",
                            "value": 1
                        }
                    }
                ]
            },
            "evaluation_parameters": {
                "prediction": "$steps.second_detection.predictions"
            },
            "next_steps": [
                "$steps.classification"
            ]
        },
        {
            "type": "ClassificationModel",
            "name": "classification",
            "image": "$steps.first_crop.crops",
            "model_id": "dog-breed-xpaq6/1"
        }
    ],
    "outputs": [
        {
            "type": "JsonField",
            "name": "dog_classification",
            "selector": "$steps.classification.predictions"
        }
    ]
}

Workflow with if statement applied on non batch-oriented input

In this test scenario we show that we can use non-batch oriented conditioning (ContinueIf block).

If statement is effectively applied on input parameter that would determine path of execution for all data passed in image input. When the value matches expectation - all dependent steps will be executed, otherwise only the independent ones.

Workflow definition
{
    "version": "1.0",
    "inputs": [
        {
            "type": "WorkflowImage",
            "name": "image"
        }
    ],
    "steps": [
        {
            "type": "ObjectDetectionModel",
            "name": "first_detection",
            "image": "$inputs.image",
            "model_id": "yolov8n-640"
        },
        {
            "type": "DetectionsTransformation",
            "name": "enlarging_boxes",
            "predictions": "$steps.first_detection.predictions",
            "operations": [
                {
                    "type": "DetectionsOffset",
                    "offset_x": 50,
                    "offset_y": 50
                }
            ]
        },
        {
            "type": "Crop",
            "name": "first_crop",
            "image": "$inputs.image",
            "predictions": "$steps.enlarging_boxes.predictions"
        },
        {
            "type": "ObjectDetectionModel",
            "name": "second_detection",
            "image": "$steps.first_crop.crops",
            "model_id": "yolov8n-640",
            "class_filter": [
                "dog"
            ]
        },
        {
            "type": "ContinueIf",
            "name": "continue_if",
            "condition_statement": {
                "type": "StatementGroup",
                "statements": [
                    {
                        "type": "BinaryStatement",
                        "left_operand": {
                            "type": "DynamicOperand",
                            "operand_name": "prediction",
                            "operations": [
                                {
                                    "type": "SequenceLength"
                                }
                            ]
                        },
                        "comparator": {
                            "type": "(Number) =="
                        },
                        "right_operand": {
                            "type": "StaticOperand",
                            "value": 1
                        }
                    }
                ]
            },
            "evaluation_parameters": {
                "prediction": "$steps.second_detection.predictions"
            },
            "next_steps": [
                "$steps.classification"
            ]
        },
        {
            "type": "ClassificationModel",
            "name": "classification",
            "image": "$steps.first_crop.crops",
            "model_id": "dog-breed-xpaq6/1"
        }
    ],
    "outputs": [
        {
            "type": "JsonField",
            "name": "dog_classification",
            "selector": "$steps.classification.predictions"
        }
    ]
}