PC inference engine backend.
This backend runs inference on a PC using Keras or TFLite models.
Parameters:
Source code in heartkit/backends/pc.py
| def __init__(self, params: HKTaskParams) -> None:
"""PC inference engine backend.
This backend runs inference on a PC using Keras or TFLite models.
Args:
params (HKTaskParams): Task parameters
"""
super().__init__(params=params)
self._inputs = None
self._outputs = None
self._model = None
|
Functions
open
This method will simply load the keras or TFLite model
Source code in heartkit/backends/pc.py
| def open(self):
"""This method will simply load the keras or TFLite model"""
if self._is_tf_model():
self._model = helia.models.load_model(self.params.model_file)
else:
with open(self.params.model_file, "rb") as fp:
model_content = fp.read()
self._model = helia.interpreters.tflite.TfLiteKerasInterpreter(model_content=model_content)
|
close
This method will unload the model
Source code in heartkit/backends/pc.py
| def close(self):
"""This method will unload the model"""
self._model = None
|
set_inputs(inputs: NDArray)
Set inputs for inference
Parameters:
Source code in heartkit/backends/pc.py
| def set_inputs(self, inputs: npt.NDArray):
"""Set inputs for inference
Args:
inputs (npt.NDArray): Inputs for inference
"""
self._inputs = inputs
|
Perform inference on the model
Source code in heartkit/backends/pc.py
| def perform_inference(self):
"""Perform inference on the model"""
if self._is_tf_model():
self._outputs = self._model.predict(np.expand_dims(self._inputs, 0), verbose=0).squeeze(0)
else:
self._outputs = self._model.predict(self._inputs)
|
get_outputs
get_outputs() -> npt.NDArray
Get outputs from inference
Returns:
-
NDArray
–
npt.NDArray: Outputs from inference
Source code in heartkit/backends/pc.py
| def get_outputs(self) -> npt.NDArray:
"""Get outputs from inference
Returns:
npt.NDArray: Outputs from inference
"""
return self._outputs
|