-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #615 from roboflow/add-inference-ids-detection-blocks
Add inference_ids to model blocks
- Loading branch information
Showing
6 changed files
with
229 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
tests/workflows/integration_tests/execution/test_workflow_inference_id_response.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from inference.core.env import WORKFLOWS_MAX_CONCURRENT_STEPS | ||
from inference.core.managers.base import ModelManager | ||
from inference.core.workflows.core_steps.common.entities import StepExecutionMode | ||
from inference.core.workflows.execution_engine.core import ExecutionEngine | ||
|
||
DETECTION_PLUS_CLASSIFICATION_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [{"type": "WorkflowImage", "name": "image"}], | ||
"steps": [ | ||
{ | ||
"type": "ObjectDetectionModel", | ||
"name": "general_detection", | ||
"image": "$inputs.image", | ||
"model_id": "yolov8n-640", | ||
"class_filter": ["dog"], | ||
}, | ||
{ | ||
"type": "Crop", | ||
"name": "cropping", | ||
"image": "$inputs.image", | ||
"predictions": "$steps.general_detection.predictions", | ||
}, | ||
{ | ||
"type": "ClassificationModel", | ||
"name": "breds_classification", | ||
"image": "$steps.cropping.crops", | ||
"model_id": "dog-breed-xpaq6/1", | ||
}, | ||
], | ||
"outputs": [ | ||
{ | ||
"type": "JsonField", | ||
"name": "predictions", | ||
"selector": "$steps.breds_classification.predictions", | ||
}, | ||
], | ||
} | ||
|
||
OBJECT_DETECTION_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [{"type": "WorkflowImage", "name": "image"}], | ||
"steps": [ | ||
{ | ||
"type": "ObjectDetectionModel", | ||
"name": "general_detection", | ||
"image": "$inputs.image", | ||
"model_id": "yolov8n-640", | ||
"class_filter": ["dog"], | ||
}, | ||
], | ||
"outputs": [ | ||
{ | ||
"type": "JsonField", | ||
"name": "predictions", | ||
"coordinates_system": "own", | ||
"selector": "$steps.general_detection.predictions", | ||
} | ||
], | ||
} | ||
|
||
INSTANCE_SEGMENTATION_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [{"type": "WorkflowImage", "name": "image"}], | ||
"steps": [ | ||
{ | ||
"type": "InstanceSegmentationModel", | ||
"name": "instance_segmentation", | ||
"image": "$inputs.image", | ||
"model_id": "yolov8n-640", | ||
}, | ||
], | ||
"outputs": [ | ||
{ | ||
"type": "JsonField", | ||
"name": "predictions", | ||
"selector": "$steps.instance_segmentation.*", | ||
} | ||
], | ||
} | ||
|
||
|
||
@pytest.mark.workflows | ||
def test_detection_plus_classification_workflow_with_inference_id( | ||
model_manager: ModelManager, | ||
dogs_image: np.ndarray, | ||
roboflow_api_key: str, | ||
) -> None: | ||
# given | ||
workflow_init_parameters = { | ||
"workflows_core.model_manager": model_manager, | ||
"workflows_core.api_key": roboflow_api_key, | ||
"workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
} | ||
execution_engine = ExecutionEngine.init( | ||
workflow_definition=DETECTION_PLUS_CLASSIFICATION_WORKFLOW, | ||
init_parameters=workflow_init_parameters, | ||
max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
) | ||
|
||
# when | ||
result = execution_engine.run( | ||
runtime_parameters={ | ||
"image": dogs_image, | ||
} | ||
) | ||
|
||
# then | ||
assert ( | ||
len(result[0]["predictions"]) == 2 | ||
), "Expected 2 dogs crops on input image, hence 2 nested classification results" | ||
|
||
for prediction in result[0]["predictions"]: | ||
assert "inference_id" in prediction, "Expected inference_id in each prediction" | ||
assert prediction["inference_id"] is not None, "Expected non-null inference_id" | ||
|
||
assert [result[0]["predictions"][0]["top"], result[0]["predictions"][1]["top"]] == [ | ||
"116.Parson_russell_terrier", | ||
"131.Wirehaired_pointing_griffon", | ||
], "Expected predictions to be as measured in reference run" | ||
|
||
|
||
@pytest.mark.workflows | ||
def test_object_detection_workflow_with_inference_id( | ||
model_manager: ModelManager, | ||
dogs_image: np.ndarray, | ||
roboflow_api_key: str, | ||
) -> None: | ||
# given | ||
workflow_init_parameters = { | ||
"workflows_core.model_manager": model_manager, | ||
"workflows_core.api_key": roboflow_api_key, | ||
"workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
} | ||
execution_engine = ExecutionEngine.init( | ||
workflow_definition=OBJECT_DETECTION_WORKFLOW, | ||
init_parameters=workflow_init_parameters, | ||
max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
) | ||
|
||
# when | ||
result = execution_engine.run( | ||
runtime_parameters={ | ||
"image": dogs_image, | ||
} | ||
) | ||
|
||
# then | ||
assert len(result[0]["predictions"]) == 2, "Expected 2 predictions" | ||
assert ( | ||
result[0]["predictions"][0]["inference_id"] is not None | ||
), "Expected non-null inference_id" | ||
assert ( | ||
result[0]["predictions"][1]["inference_id"] is not None | ||
), "Expected non-null inference_id" | ||
|
||
|
||
@pytest.mark.workflows | ||
def test_instance_segmentation_workflow_with_inference_id( | ||
model_manager: ModelManager, | ||
dogs_image: np.ndarray, | ||
roboflow_api_key: str, | ||
) -> None: | ||
# given | ||
workflow_init_parameters = { | ||
"workflows_core.model_manager": model_manager, | ||
"workflows_core.api_key": roboflow_api_key, | ||
"workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
} | ||
execution_engine = ExecutionEngine.init( | ||
workflow_definition=INSTANCE_SEGMENTATION_WORKFLOW, | ||
init_parameters=workflow_init_parameters, | ||
max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
) | ||
|
||
# when | ||
result = execution_engine.run( | ||
runtime_parameters={ | ||
"image": dogs_image, | ||
} | ||
) | ||
|
||
# then | ||
assert len(result[0]["predictions"]) == 2, "Expected 2 predictions" | ||
assert ( | ||
result[0]["predictions"].get("inference_id") is not None | ||
), "Expected non-null inference_id" |