Example Workflows - Workflows with data transformations¶
Below you can find example workflows you can use as inspiration to build your apps.
Workflow with detections class remapping¶
This workflow presents how to use Detections Transformation block that is going to
change the name of the following classes: apple
, banana
into fruit
.
In this example, we use non-strict mapping, causing new class fruit
to be added to
pool of classes - you can see that if banana
or apple
is detected, the
class name changes to fruit
and class id is 1024.
You can test the execution submitting image like this.
Workflow definition
{
"version": "1.0",
"inputs": [
{
"type": "WorkflowImage",
"name": "image"
},
{
"type": "WorkflowParameter",
"name": "confidence",
"default_value": 0.4
}
],
"steps": [
{
"type": "ObjectDetectionModel",
"name": "model",
"image": "$inputs.image",
"model_id": "yolov8n-640",
"confidence": "$inputs.confidence"
},
{
"type": "DetectionsTransformation",
"name": "class_rename",
"predictions": "$steps.model.predictions",
"operations": [
{
"type": "DetectionsRename",
"strict": false,
"class_map": {
"apple": "fruit",
"banana": "fruit"
}
}
]
}
],
"outputs": [
{
"type": "JsonField",
"name": "original_predictions",
"selector": "$steps.model.predictions"
},
{
"type": "JsonField",
"name": "renamed_predictions",
"selector": "$steps.class_rename.predictions"
}
]
}
Workflow with detections filtering¶
This example presents how to use Detections Transformation block to build workflow that is going to filter predictions based on:
-
predicted classes
-
size of predicted bounding box relative to size of input image
Workflow definition
{
"version": "1.0",
"inputs": [
{
"type": "WorkflowImage",
"name": "image"
},
{
"type": "WorkflowParameter",
"name": "model_id"
},
{
"type": "WorkflowParameter",
"name": "confidence",
"default_value": 0.3
},
{
"type": "WorkflowParameter",
"name": "classes"
}
],
"steps": [
{
"type": "RoboflowObjectDetectionModel",
"name": "detection",
"image": "$inputs.image",
"model_id": "$inputs.model_id",
"confidence": "$inputs.confidence"
},
{
"type": "DetectionsTransformation",
"name": "filtering",
"predictions": "$steps.detection.predictions",
"operations": [
{
"type": "DetectionsFilter",
"filter_operation": {
"type": "StatementGroup",
"operator": "and",
"statements": [
{
"type": "BinaryStatement",
"left_operand": {
"type": "DynamicOperand",
"operations": [
{
"type": "ExtractDetectionProperty",
"property_name": "class_name"
}
]
},
"comparator": {
"type": "in (Sequence)"
},
"right_operand": {
"type": "DynamicOperand",
"operand_name": "classes"
}
},
{
"type": "BinaryStatement",
"left_operand": {
"type": "DynamicOperand",
"operations": [
{
"type": "ExtractDetectionProperty",
"property_name": "size"
}
]
},
"comparator": {
"type": "(Number) >="
},
"right_operand": {
"type": "DynamicOperand",
"operand_name": "image",
"operations": [
{
"type": "ExtractImageProperty",
"property_name": "size"
},
{
"type": "Multiply",
"other": 0.02
}
]
}
}
]
}
}
],
"operations_parameters": {
"image": "$inputs.image",
"classes": "$inputs.classes"
}
}
],
"outputs": [
{
"type": "JsonField",
"name": "result",
"selector": "$steps.filtering.*"
}
]
}
Instance Segmentation results with background subtracted¶
This example showcases how to extract all instances detected by instance segmentation model as separate crops without background.
Workflow definition
{
"version": "1.0",
"inputs": [
{
"type": "WorkflowImage",
"name": "image"
},
{
"type": "WorkflowParameter",
"name": "model_id",
"default_value": "yolov8n-seg-640"
},
{
"type": "WorkflowParameter",
"name": "confidence",
"default_value": 0.4
}
],
"steps": [
{
"type": "roboflow_core/roboflow_instance_segmentation_model@v2",
"name": "segmentation",
"image": "$inputs.image",
"model_id": "$inputs.model_id",
"confidence": "$inputs.confidence"
},
{
"type": "roboflow_core/dynamic_crop@v1",
"name": "cropping",
"image": "$inputs.image",
"predictions": "$steps.segmentation.predictions",
"mask_opacity": 1.0
}
],
"outputs": [
{
"type": "JsonField",
"name": "crops",
"selector": "$steps.cropping.crops"
},
{
"type": "JsonField",
"name": "predictions",
"selector": "$steps.segmentation.predictions"
}
]
}
Workflow with detections sorting¶
This workflow presents how to use Detections Transformation block that is going to align predictions from object detection model such that results are sorted ascending regarding confidence.
Workflow definition
{
"version": "1.0",
"inputs": [
{
"type": "WorkflowImage",
"name": "image"
},
{
"type": "WorkflowParameter",
"name": "model_id"
},
{
"type": "WorkflowParameter",
"name": "confidence",
"default_value": 0.75
},
{
"type": "WorkflowParameter",
"name": "classes"
}
],
"steps": [
{
"type": "RoboflowObjectDetectionModel",
"name": "detection",
"image": "$inputs.image",
"model_id": "$inputs.model_id",
"confidence": "$inputs.confidence"
},
{
"type": "DetectionsTransformation",
"name": "sorting",
"predictions": "$steps.detection.predictions",
"operations": [
{
"type": "SortDetections",
"mode": "confidence",
"ascending": true
}
],
"operations_parameters": {
"image": "$inputs.image",
"classes": "$inputs.classes"
}
}
],
"outputs": [
{
"type": "JsonField",
"name": "result",
"selector": "$steps.sorting.*"
}
]
}