diff --git a/inference/core/entities/responses/inference.py b/inference/core/entities/responses/inference.py index cc66a19ccd..6dddccd322 100644 --- a/inference/core/entities/responses/inference.py +++ b/inference/core/entities/responses/inference.py @@ -262,9 +262,12 @@ class ClassificationInferenceResponse(CvInferenceResponse, WithVisualizationResp """ predictions: List[ClassificationPrediction] - top: str = Field(description="The top predicted class label") + top: str = Field( + description="The top predicted class label", default="" + ) # Not making this field optional to avoid breaking change - in other parts of the codebase `model_dump` is called with `exclude_none=True` confidence: float = Field( - description="The confidence of the top predicted class label" + description="The confidence of the top predicted class label", + default=0.0, ) parent_id: Optional[str] = Field( description="Identifier of parent image region. Useful when stack of detection-models is in use to refer the RoI being the input to inference", diff --git a/inference/core/models/classification_base.py b/inference/core/models/classification_base.py index e71acd4eb3..bef017b1b0 100644 --- a/inference/core/models/classification_base.py +++ b/inference/core/models/classification_base.py @@ -350,6 +350,8 @@ def make_response( results = [] for i, cls_name in enumerate(self.class_names): score = float(preds[i]) + if score < confidence_threshold: + continue pred = { "class_id": i, "class": cls_name, @@ -363,8 +365,8 @@ def make_response( width=img_dims[ind][1], height=img_dims[ind][0] ), predictions=results, - top=results[0]["class"], - confidence=results[0]["confidence"], + top=results[0]["class"] if results else "", + confidence=results[0]["confidence"] if results else 0.0, ) responses.append(response) diff --git a/inference/core/version.py b/inference/core/version.py index 91dcee7178..d66cfa94d4 100644 --- a/inference/core/version.py +++ b/inference/core/version.py @@ -1,4 +1,4 @@ -__version__ = "0.38.0" +__version__ = "0.39.0rc1" if __name__ == "__main__": diff --git a/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v1/test_workflow_for_classification.py b/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v1/test_workflow_for_classification.py index e25b485deb..1fbc15c46a 100644 --- a/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v1/test_workflow_for_classification.py +++ b/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v1/test_workflow_for_classification.py @@ -19,6 +19,7 @@ "name": "classifier", "image": "$inputs.image", "model_id": "$inputs.model_id", + "confidence": 0.09, } ], "outputs": [ @@ -98,6 +99,7 @@ def test_multi_class_classification_workflow( "name": "classifier", "image": "$inputs.image", "model_id": "$inputs.model_id", + "confidence": 0.5, } ], "outputs": [ diff --git a/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v2/test_workflow_for_classification.py b/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v2/test_workflow_for_classification.py index 40f5e7675c..d68c659941 100644 --- a/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v2/test_workflow_for_classification.py +++ b/tests/inference/hosted_platform_tests/workflows_examples/roboflow_models/v2/test_workflow_for_classification.py @@ -19,6 +19,7 @@ "name": "classifier", "image": "$inputs.image", "model_id": "$inputs.model_id", + "confidence": 0.09, } ], "outputs": [ @@ -98,6 +99,7 @@ def test_multi_class_classification_workflow( "name": "classifier", "image": "$inputs.image", "model_id": "$inputs.model_id", + "confidence": 0.5, } ], "outputs": [ diff --git a/tests/workflows/integration_tests/execution/test_workflow_detection_plus_classification.py b/tests/workflows/integration_tests/execution/test_workflow_detection_plus_classification.py index 78c8bf597d..2be00e9cf6 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_detection_plus_classification.py +++ b/tests/workflows/integration_tests/execution/test_workflow_detection_plus_classification.py @@ -31,6 +31,7 @@ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, ], "outputs": [ @@ -103,6 +104,7 @@ def test_legacy_detection_plus_classification_workflow_when_minimal_valid_input_ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, ], "outputs": [ diff --git a/tests/workflows/integration_tests/execution/test_workflow_inference_id_response.py b/tests/workflows/integration_tests/execution/test_workflow_inference_id_response.py index 6382386175..de0838cbc9 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_inference_id_response.py +++ b/tests/workflows/integration_tests/execution/test_workflow_inference_id_response.py @@ -28,6 +28,7 @@ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, ], "outputs": [ diff --git a/tests/workflows/integration_tests/execution/test_workflow_with_active_learning_sink.py b/tests/workflows/integration_tests/execution/test_workflow_with_active_learning_sink.py index cbee95f501..4b0db3b6dd 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_with_active_learning_sink.py +++ b/tests/workflows/integration_tests/execution/test_workflow_with_active_learning_sink.py @@ -47,6 +47,7 @@ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, { "type": "roboflow_core/roboflow_dataset_upload@v2", diff --git a/tests/workflows/integration_tests/execution/test_workflow_with_custom_expression_built_for_detections_with_specialised_classification.py b/tests/workflows/integration_tests/execution/test_workflow_with_custom_expression_built_for_detections_with_specialised_classification.py index d86344696b..9489932115 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_with_custom_expression_built_for_detections_with_specialised_classification.py +++ b/tests/workflows/integration_tests/execution/test_workflow_with_custom_expression_built_for_detections_with_specialised_classification.py @@ -31,6 +31,7 @@ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, { "type": "DetectionsClassesReplacement", diff --git a/tests/workflows/integration_tests/execution/test_workflow_with_detections_classes_replacement_by_specialised_classification.py b/tests/workflows/integration_tests/execution/test_workflow_with_detections_classes_replacement_by_specialised_classification.py index d67201f7c6..f6cd3532d0 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_with_detections_classes_replacement_by_specialised_classification.py +++ b/tests/workflows/integration_tests/execution/test_workflow_with_detections_classes_replacement_by_specialised_classification.py @@ -31,6 +31,7 @@ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, { "type": "DetectionsClassesReplacement", diff --git a/tests/workflows/integration_tests/execution/test_workflow_with_property_extraction.py b/tests/workflows/integration_tests/execution/test_workflow_with_property_extraction.py index 6bcff84871..21aad88846 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_with_property_extraction.py +++ b/tests/workflows/integration_tests/execution/test_workflow_with_property_extraction.py @@ -212,6 +212,7 @@ def test_workflow_with_extraction_of_classes_for_detections( "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, { "type": "PropertyDefinition", diff --git a/tests/workflows/integration_tests/execution/test_workflow_with_two_stage_models_and_flow_control.py b/tests/workflows/integration_tests/execution/test_workflow_with_two_stage_models_and_flow_control.py index 721443c098..8bfd4aea62 100644 --- a/tests/workflows/integration_tests/execution/test_workflow_with_two_stage_models_and_flow_control.py +++ b/tests/workflows/integration_tests/execution/test_workflow_with_two_stage_models_and_flow_control.py @@ -27,6 +27,7 @@ "name": "breds_classification", "image": "$steps.cropping.crops", "model_id": "dog-breed-xpaq6/1", + "confidence": 0.09, }, { "type": "roboflow_core/continue_if@v1",