-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Rename Classes UQL Operation #656
Changes from 5 commits
96c2ddc
385c63f
8eaf988
d816df7
090a863
3972fe8
e68e377
ea891c5
ca0e01a
d9abeb1
fbc8db1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. great tests coverage There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PawelPeczek-Roboflow Hey Pawel, I couldn't figure out or find a good example of passing Input Parameters into UQL operations for tests. Instead I created a hacky work around with parameterized tests to replace the Workflow Specification to test scenarios. Feel free to change this if you'd like; as I would also like to learn how to pass input parameters into UQL operations for future work. |
||
import supervision as sv | ||
|
||
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 | ||
|
||
CLASS_RENAME_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [ | ||
{ | ||
"type": "WorkflowImage", | ||
"name": "image" | ||
}, | ||
{ | ||
"type": "WorkflowParameter", | ||
"name": "model_id" | ||
}, | ||
{ | ||
"type": "WorkflowParameter", | ||
"name": "confidence", | ||
"default_value": 0.4 | ||
}, | ||
{ | ||
"type": "WorkflowParameter", | ||
"name": "classes" | ||
}, | ||
], | ||
"steps": [ | ||
{ | ||
"type": "ObjectDetectionModel", | ||
"name": "model", | ||
"image": "$inputs.image", | ||
"model_id": "$inputs.model_id", | ||
"confidence": "$inputs.confidence", | ||
}, | ||
{ | ||
"type": "DetectionsTransformation", | ||
"name": "class_rename", | ||
"predictions": "$steps.model.predictions", | ||
"operations": [ | ||
{ | ||
"type": "DetectionsRename", | ||
"class_map": { | ||
"orange": "fruit", | ||
"banana": "fruit", | ||
"apple": "fruit" | ||
} | ||
} | ||
], | ||
}, | ||
], | ||
"outputs": [ | ||
{ | ||
"type": "JsonField", | ||
"name": "original_predictions", | ||
"selector": "$steps.model.predictions", | ||
}, | ||
{ | ||
"type": "JsonField", | ||
"name": "renamed_predictions", | ||
"selector": "$steps.class_rename.predictions", | ||
}, | ||
], | ||
} | ||
|
||
|
||
EXPECTED_ORIGINAL_CLASSES = np.array( | ||
[ | ||
"apple", | ||
"apple", | ||
"apple", | ||
"orange", | ||
"banana" | ||
] | ||
) | ||
EXPECTED_RENAMED_CLASSES = np.array( | ||
[ | ||
"fruit", | ||
"fruit", | ||
"fruit", | ||
"fruit", | ||
"fruit" | ||
] | ||
) | ||
|
||
|
||
def test_class_rename_workflow_to_have_correct_classes( | ||
model_manager: ModelManager, | ||
fruit_image: np.ndarray, | ||
) -> None: | ||
# given | ||
workflow_init_parameters = { | ||
"workflows_core.model_manager": model_manager, | ||
"workflows_core.api_key": None, | ||
"workflows_core.step_execution_mode": StepExecutionMode.LOCAL, | ||
} | ||
execution_engine = ExecutionEngine.init( | ||
workflow_definition=CLASS_RENAME_WORKFLOW, | ||
init_parameters=workflow_init_parameters, | ||
max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS, | ||
) | ||
|
||
# when | ||
result = execution_engine.run( | ||
runtime_parameters={ | ||
"image": fruit_image, | ||
"model_id": "yolov8n-640", | ||
} | ||
) | ||
|
||
# then | ||
assert isinstance(result, list), "Expected result to be list" | ||
assert len(result) == 1, "Single image provided - single output expected" | ||
|
||
original_predictions: sv.Detections = result[0]["original_predictions"] | ||
renamed_predictions: sv.Detections = result[0]["renamed_predictions"] | ||
|
||
assert len(original_predictions) == len(EXPECTED_ORIGINAL_CLASSES), "length of original predictions match expected length" | ||
assert len(renamed_predictions) == len(EXPECTED_RENAMED_CLASSES), "length of renamed predictions match expected length " | ||
|
||
assert np.array_equal(EXPECTED_ORIGINAL_CLASSES, original_predictions.data["class_name"]), "Expected original classes to match predicted classes" | ||
assert np.array_equal(EXPECTED_RENAMED_CLASSES, renamed_predictions.data["class_name"]), "Expected renamed classes to match block class renaming" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please report image credits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complete