-
Notifications
You must be signed in to change notification settings - Fork 140
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 #823 from roboflow/fix/aligning_models_v2_into_bas…
…e64_payloads Fix issue with Workflows blocks for Roboflow models v2 not using base64
- Loading branch information
Showing
23 changed files
with
1,036 additions
and
19 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
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
Empty file.
Empty file.
174 changes: 174 additions & 0 deletions
174
..._platform_tests/workflows_examples/roboflow_models/v1/test_workflow_for_classification.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,174 @@ | ||
import numpy as np | ||
import pytest | ||
|
||
from inference_sdk import InferenceHTTPClient | ||
from tests.inference.hosted_platform_tests.conftest import ( | ||
ROBOFLOW_API_KEY, | ||
PlatformEnvironment, | ||
) | ||
|
||
MULTI_CLASS_CLASSIFICATION_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [ | ||
{"type": "WorkflowImage", "name": "image"}, | ||
{"type": "WorkflowParameter", "name": "model_id"}, | ||
], | ||
"steps": [ | ||
{ | ||
"type": "roboflow_core/roboflow_classification_model@v1", | ||
"name": "classifier", | ||
"image": "$inputs.image", | ||
"model_id": "$inputs.model_id", | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
"type": "JsonField", | ||
"name": "predictions", | ||
"selector": "$steps.classifier.predictions", | ||
}, | ||
{ | ||
"type": "JsonField", | ||
"name": "inference_id", | ||
"selector": "$steps.classifier.inference_id", | ||
}, | ||
], | ||
} | ||
|
||
MULTI_CLASS_CLASSIFICATION_RESULTS_FOR_ENVIRONMENT = { | ||
PlatformEnvironment.ROBOFLOW_STAGING: [ | ||
0.3673, | ||
0.593, | ||
], | ||
PlatformEnvironment.ROBOFLOW_PLATFORM: [0.8252, 0.9962], | ||
} | ||
|
||
|
||
@pytest.mark.flaky(retries=4, delay=1) | ||
def test_multi_class_classification_workflow( | ||
platform_environment: PlatformEnvironment, | ||
classification_service_url: str, | ||
multi_class_classification_model_id: str, | ||
dogs_image: np.ndarray, | ||
license_plate_image: np.ndarray, | ||
) -> None: | ||
# given | ||
client = InferenceHTTPClient( | ||
api_url=classification_service_url, | ||
api_key=ROBOFLOW_API_KEY, | ||
) | ||
|
||
# when | ||
result = client.run_workflow( | ||
specification=MULTI_CLASS_CLASSIFICATION_WORKFLOW, | ||
images={ | ||
"image": [dogs_image, license_plate_image], | ||
}, | ||
parameters={ | ||
"model_id": multi_class_classification_model_id, | ||
}, | ||
) | ||
|
||
# then | ||
assert len(result) == 2, "2 images submitted, expected two outputs" | ||
assert set(result[0].keys()) == { | ||
"predictions", | ||
"inference_id", | ||
}, "Expected all outputs to be registered" | ||
assert set(result[1].keys()) == { | ||
"predictions", | ||
"inference_id", | ||
}, "Expected all outputs to be registered" | ||
unique_inference_ids = {r["inference_id"] for r in result} | ||
assert len(unique_inference_ids) == 2, "Expected unique inference ids granted" | ||
predicted_confidences = [r["predictions"]["confidence"] for r in result] | ||
assert np.allclose( | ||
predicted_confidences, | ||
MULTI_CLASS_CLASSIFICATION_RESULTS_FOR_ENVIRONMENT[platform_environment], | ||
atol=1e-3, | ||
), "Expected classification predictions to match expectations" | ||
|
||
|
||
MULTI_LABEL_CLASSIFICATION_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [ | ||
{"type": "WorkflowImage", "name": "image"}, | ||
{"type": "WorkflowParameter", "name": "model_id"}, | ||
], | ||
"steps": [ | ||
{ | ||
"type": "roboflow_core/roboflow_multi_label_classification_model@v1", | ||
"name": "classifier", | ||
"image": "$inputs.image", | ||
"model_id": "$inputs.model_id", | ||
} | ||
], | ||
"outputs": [ | ||
{ | ||
"type": "JsonField", | ||
"name": "predictions", | ||
"selector": "$steps.classifier.predictions", | ||
}, | ||
{ | ||
"type": "JsonField", | ||
"name": "inference_id", | ||
"selector": "$steps.classifier.inference_id", | ||
}, | ||
], | ||
} | ||
|
||
|
||
MULTI_LABEL_CLASSIFICATION_RESULTS_FOR_ENVIRONMENT = { | ||
PlatformEnvironment.ROBOFLOW_STAGING: [ | ||
{"dog"}, | ||
{"cat", "dog"}, | ||
], | ||
PlatformEnvironment.ROBOFLOW_PLATFORM: [ | ||
{"dog"}, | ||
set(), | ||
], | ||
} | ||
|
||
|
||
@pytest.mark.flaky(retries=4, delay=1) | ||
def test_multi_label_classification_workflow( | ||
platform_environment: PlatformEnvironment, | ||
classification_service_url: str, | ||
classification_model_id: str, | ||
dogs_image: np.ndarray, | ||
license_plate_image: np.ndarray, | ||
) -> None: | ||
# given | ||
client = InferenceHTTPClient( | ||
api_url=classification_service_url, | ||
api_key=ROBOFLOW_API_KEY, | ||
) | ||
|
||
# when | ||
result = client.run_workflow( | ||
specification=MULTI_LABEL_CLASSIFICATION_WORKFLOW, | ||
images={ | ||
"image": [dogs_image, license_plate_image], | ||
}, | ||
parameters={ | ||
"model_id": classification_model_id, | ||
}, | ||
) | ||
|
||
# then | ||
assert len(result) == 2, "2 images submitted, expected two outputs" | ||
assert set(result[0].keys()) == { | ||
"predictions", | ||
"inference_id", | ||
}, "Expected all outputs to be registered" | ||
assert set(result[1].keys()) == { | ||
"predictions", | ||
"inference_id", | ||
}, "Expected all outputs to be registered" | ||
unique_inference_ids = {r["inference_id"] for r in result} | ||
assert len(unique_inference_ids) == 2, "Expected unique inference ids granted" | ||
predicted_classes = [set(r["predictions"]["predicted_classes"]) for r in result] | ||
assert ( | ||
predicted_classes | ||
== MULTI_LABEL_CLASSIFICATION_RESULTS_FOR_ENVIRONMENT[platform_environment] | ||
) |
Oops, something went wrong.