Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new Python API of OpenVINO #345

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
Core,
Model,
CompiledModel,
InferRequest,
)
from nebullvm.optional_modules.tensorflow import tensorflow as tf
from nebullvm.optional_modules.torch import torch
Expand Down Expand Up @@ -52,7 +51,6 @@ class OpenVinoInferenceLearner(BaseInferenceLearner, ABC):
def __init__(
self,
compiled_model: CompiledModel,
infer_request: InferRequest,
input_keys: List,
output_keys: List,
description_file: str,
Expand All @@ -62,7 +60,6 @@ def __init__(
):
super().__init__(**kwargs)
self.compiled_model = compiled_model
self.infer_request = infer_request
self.input_keys = input_keys
self.output_keys = output_keys
self.device = device
Expand Down Expand Up @@ -147,7 +144,6 @@ def from_model_name(
model.reshape(dynamic_shape)

compiled_model = core.compile_model(model=model, device_name="CPU")
infer_request = compiled_model.create_infer_request()

input_keys = list(
map(lambda obj: obj.get_any_name(), compiled_model.inputs)
Expand All @@ -158,7 +154,6 @@ def from_model_name(

return cls(
compiled_model,
infer_request,
input_keys,
output_keys,
input_tfms=input_tfms,
Expand Down Expand Up @@ -240,18 +235,15 @@ def _predict_array(
input_arrays: Generator[np.ndarray, None, None],
) -> Generator[np.ndarray, None, None]:

results = self.infer_request.infer(
results = self.compiled_model(
inputs={
input_key: input_array
for input_key, input_array in zip(
self.input_keys, input_arrays
)
}
},
shared_memory=True, # always enabled
)
results = {
output_key.get_any_name(): output_arr
for output_key, output_arr in results.items()
}

return (results[output_key] for output_key in self.output_keys)

Expand Down