Skip to content

Commit

Permalink
Merge pull request #548 from roboflow/cover-model-usage-in-usage-coll…
Browse files Browse the repository at this point in the history
…ector

Wrap call to 'predict' with usage_collector
  • Loading branch information
grzegorz-roboflow authored Aug 22, 2024
2 parents 8ae7652 + b98c867 commit 3c0200f
Show file tree
Hide file tree
Showing 18 changed files with 375 additions and 209 deletions.
4 changes: 4 additions & 0 deletions inference/core/entities/requests/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class WorkflowInferenceRequest(BaseModel):

class WorkflowSpecificationInferenceRequest(WorkflowInferenceRequest):
specification: dict
is_preview: bool = Field(
default=False,
description="Reserved, used internally by Roboflow to distinguish between preview and non-preview runs",
)


class DescribeBlocksRequest(BaseModel):
Expand Down
1 change: 0 additions & 1 deletion inference/core/interfaces/stream/inference_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
from inference.core.workflows.core_steps.common.entities import StepExecutionMode
from inference.models.aliases import resolve_roboflow_model_alias
from inference.models.utils import ROBOFLOW_MODEL_TYPES, get_model
from inference.usage_tracking.collector import usage_collector

INFERENCE_PIPELINE_CONTEXT = "inference_pipeline"
SOURCE_CONNECTION_ATTEMPT_FAILED_EVENT = "SOURCE_CONNECTION_ATTEMPT_FAILED"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def default_process_frame(
predictions = wrap_in_list(
model.infer(
[f.image for f in video_frame],
usage_fps=video_frame[0].fps,
usage_api_key=model.api_key,
**postprocessing_args,
)
)
Expand Down
2 changes: 2 additions & 0 deletions inference/core/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from inference.core.entities.requests.inference import InferenceRequest
from inference.core.entities.responses.inference import InferenceResponse
from inference.core.models.types import PreprocessReturnMetadata
from inference.usage_tracking.collector import usage_collector


class BaseInference:
Expand All @@ -15,6 +16,7 @@ class BaseInference:
This class provides a basic interface for inference tasks.
"""

@usage_collector
def infer(self, image: Any, **kwargs) -> Any:
"""Runs inference on given data.
- image:
Expand Down
2 changes: 1 addition & 1 deletion inference/core/models/roboflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def validate_model(self) -> None:
def run_test_inference(self) -> None:
test_image = (np.random.rand(1024, 1024, 3) * 255).astype(np.uint8)
logger.debug(f"Running test inference. Image size: {test_image.shape}")
result = self.infer(test_image)
result = self.infer(test_image, usage_inference_test_run=True)
logger.debug(f"Test inference finished.")
return result

Expand Down
2 changes: 1 addition & 1 deletion inference/core/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.16.2"
__version__ = "0.16.3"


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions inference/core/workflows/execution_engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ def run(
self,
runtime_parameters: Dict[str, Any],
fps: float = 0,
_is_preview: bool = False,
) -> List[Dict[str, Any]]:
return self._engine.run(
runtime_parameters=runtime_parameters,
fps=fps,
_is_preview=_is_preview,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ def run(
self,
runtime_parameters: Dict[str, Any],
fps: float = 0,
_is_preview: bool = False,
) -> List[Dict[str, Any]]:
pass
2 changes: 2 additions & 0 deletions inference/core/workflows/execution_engine/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def run(
self,
runtime_parameters: Dict[str, Any],
fps: float = 0,
_is_preview: bool = False,
) -> List[Dict[str, Any]]:
runtime_parameters = assemble_runtime_parameters(
runtime_parameters=runtime_parameters,
Expand All @@ -77,4 +78,5 @@ def run(
max_concurrent_steps=self._max_concurrent_steps,
usage_fps=fps,
usage_workflow_id=self._workflow_id,
usage_workflow_preview=_is_preview,
)
Loading

0 comments on commit 3c0200f

Please sign in to comment.