Skip to content

Commit

Permalink
Merge pull request #1025 from roboflow/aspect-ratio-operation
Browse files Browse the repository at this point in the history
Aspect ratio operation
  • Loading branch information
PawelPeczek-Roboflow authored Feb 13, 2025
2 parents d278028 + 62e902e commit cd5f0b7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class ImageProperty(Enum):
SIZE = "size"
HEIGHT = "height"
WIDTH = "width"
ASPECT_RATIO = "aspect_ratio"


class DetectionsSelectionMode(Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
* image.numpy_image.shape[1],
ImageProperty.HEIGHT: lambda image: image.numpy_image.shape[0],
ImageProperty.WIDTH: lambda image: image.numpy_image.shape[1],
ImageProperty.ASPECT_RATIO: lambda image: (
image.numpy_image.shape[1] / image.numpy_image.shape[0]
if image.numpy_image.shape[0] != 0
else 0
),
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,3 +723,54 @@ def test_workflow_when_there_is_faulty_application_of_aggregation_step_at_batch_
init_parameters=workflow_init_parameters,
max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS,
)


WORKFLOW_WITH_ASPECT_RATIO_EXTRACTION = {
"version": "1.0",
"inputs": [{"type": "WorkflowImage", "name": "image"}],
"steps": [
{
"type": "PropertyDefinition",
"name": "property_extraction",
"data": "$inputs.image",
"operations": [
{"type": "ExtractImageProperty", "property_name": "aspect_ratio"}
],
},
],
"outputs": [
{
"type": "JsonField",
"name": "aspect_ratio",
"selector": "$steps.property_extraction.output",
},
],
}


def test_workflow_with_aspect_ratio_extraction_with_valid_input(
model_manager: ModelManager,
license_plate_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=WORKFLOW_WITH_ASPECT_RATIO_EXTRACTION,
init_parameters=workflow_init_parameters,
max_concurrent_steps=WORKFLOWS_MAX_CONCURRENT_STEPS,
)

# when
result = execution_engine.run(runtime_parameters={"image": license_plate_image})

# then
assert isinstance(result, list), "Expected list to be delivered"
assert len(result) == 1, "Expected 1 element in the output for one input image"
assert set(result[0].keys()) == {
"aspect_ratio",
}, "Expected all declared outputs to be delivered"
assert result[0]["aspect_ratio"] == 1.5, "Expected aspect ratio to be 1.5"

0 comments on commit cd5f0b7

Please sign in to comment.