From 0167e548f7e5df2e77befb7de54c459d2232a93e Mon Sep 17 00:00:00 2001 From: Bartek Szmelczynski Date: Thu, 21 Oct 2021 16:04:24 +0200 Subject: [PATCH] Bind exec core ov (#50) --- .../bindings/python/src/openvino/__init__.py | 1 + .../bindings/python/src/openvino/ie_api.py | 6 + .../python/src/openvino/impl/__init__.py | 1 + .../python/src/pyopenvino/core/core.cpp | 114 +++++++++ .../pyopenvino/core/{ie_core.hpp => core.hpp} | 0 .../pyopenvino/core/executable_network.cpp | 76 ++++++ ...ble_network.hpp => executable_network.hpp} | 0 .../python/src/pyopenvino/core/ie_core.cpp | 160 ------------ .../pyopenvino/core/ie_executable_network.cpp | 91 ------- .../src/pyopenvino/core/ie_infer_request.cpp | 2 +- .../python/src/pyopenvino/core/ie_version.cpp | 21 +- .../src/pyopenvino/graph/node_output.cpp | 67 +---- .../src/pyopenvino/graph/node_output.hpp | 75 +++++- .../python/src/pyopenvino/pyopenvino.cpp | 7 +- runtime/bindings/python/tests/__init__.py | 1 + runtime/bindings/python/tests/runtime.py | 44 +--- .../tests/test_inference_engine/test_core.py | 121 ++++----- .../test_executable_network.py | 229 ++++++++++++++++++ .../test_infer_request.py | 34 +-- .../test_onnx/test_onnx_external_data.py | 6 +- .../tests/test_onnx/test_onnx_import.py | 6 +- .../tests/test_onnx/utils/onnx_helpers.py | 8 +- 22 files changed, 600 insertions(+), 470 deletions(-) create mode 100644 runtime/bindings/python/src/pyopenvino/core/core.cpp rename runtime/bindings/python/src/pyopenvino/core/{ie_core.hpp => core.hpp} (100%) create mode 100644 runtime/bindings/python/src/pyopenvino/core/executable_network.cpp rename runtime/bindings/python/src/pyopenvino/core/{ie_executable_network.hpp => executable_network.hpp} (100%) delete mode 100644 runtime/bindings/python/src/pyopenvino/core/ie_core.cpp delete mode 100644 runtime/bindings/python/src/pyopenvino/core/ie_executable_network.cpp create mode 100644 runtime/bindings/python/tests/test_inference_engine/test_executable_network.py diff --git a/runtime/bindings/python/src/openvino/__init__.py b/runtime/bindings/python/src/openvino/__init__.py index 0334300387aa83..9ece8649f652e2 100644 --- a/runtime/bindings/python/src/openvino/__init__.py +++ b/runtime/bindings/python/src/openvino/__init__.py @@ -18,6 +18,7 @@ from openvino.ie_api import async_infer from openvino.ie_api import get_result from openvino.ie_api import blob_from_file +from openvino.ie_api import tensor_from_file from openvino.impl import Dimension from openvino.impl import Function diff --git a/runtime/bindings/python/src/openvino/ie_api.py b/runtime/bindings/python/src/openvino/ie_api.py index 925bc2ad5bb545..29588032458062 100644 --- a/runtime/bindings/python/src/openvino/ie_api.py +++ b/runtime/bindings/python/src/openvino/ie_api.py @@ -15,6 +15,7 @@ from openvino.pyopenvino import TBlobUint8 from openvino.pyopenvino import TensorDesc from openvino.pyopenvino import InferRequest +from openvino.pyopenvino import Tensor precision_map = {"FP32": np.float32, @@ -112,3 +113,8 @@ def blob_from_file(path_to_bin_file: str) -> BlobWrapper: array = np.fromfile(path_to_bin_file, dtype=np.uint8) tensor_desc = TensorDesc("U8", array.shape, "C") return BlobWrapper(tensor_desc, array) + +# flake8: noqa: D102 +def tensor_from_file(path: str) -> Tensor: + """The data will be read with dtype of unit8""" + return Tensor(np.fromfile(path, dtype=np.uint8)) diff --git a/runtime/bindings/python/src/openvino/impl/__init__.py b/runtime/bindings/python/src/openvino/impl/__init__.py index 641764122dc5a9..cfde3f4b3e1d66 100644 --- a/runtime/bindings/python/src/openvino/impl/__init__.py +++ b/runtime/bindings/python/src/openvino/impl/__init__.py @@ -49,4 +49,5 @@ from openvino.pyopenvino import Coordinate from openvino.pyopenvino import Output from openvino.pyopenvino import Layout +from openvino.pyopenvino import ConstOutput from openvino.pyopenvino import util diff --git a/runtime/bindings/python/src/pyopenvino/core/core.cpp b/runtime/bindings/python/src/pyopenvino/core/core.cpp new file mode 100644 index 00000000000000..35c7e54c57c0c5 --- /dev/null +++ b/runtime/bindings/python/src/pyopenvino/core/core.cpp @@ -0,0 +1,114 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "pyopenvino/core/core.hpp" + +#include +#include + +#include +#include + +#include "common.hpp" + +namespace py = pybind11; + +using ConfigMap = std::map; + +std::string to_string(py::handle handle) { + auto encodedString = PyUnicode_AsUTF8String(handle.ptr()); + return PyBytes_AsString(encodedString); +} + +void regclass_Core(py::module m) { + py::class_> cls(m, "Core"); + cls.def(py::init(), py::arg("xml_config_file") = ""); + + cls.def("set_config", + (void (ov::runtime::Core::*)(const ConfigMap&, const std::string&)) & ov::runtime::Core::set_config, + py::arg("config"), + py::arg("device_name") = ""); + + cls.def( + "compile_model", + (ov::runtime::ExecutableNetwork( + ov::runtime::Core::*)(const std::shared_ptr&, const std::string&, const ConfigMap&)) & + ov::runtime::Core::compile_model, + py::arg("network"), + py::arg("device_name"), + py::arg("config") = py::dict()); + + cls.def( + "add_extension", + [](ov::runtime::Core& self, const std::string& extension_path) { + auto extension_ptr = InferenceEngine::make_so_pointer(extension_path); + auto extension = std::dynamic_pointer_cast(extension_ptr); + self.add_extension(extension); + }, + py::arg("extension_path")); + + cls.def("get_versions", &ov::runtime::Core::get_versions); + + cls.def("read_model", + (std::shared_ptr(ov::runtime::Core::*)(const std::string&, const std::string&) const) & + ov::runtime::Core::read_model, + py::arg("model"), + py::arg("weights") = ""); + + cls.def( + "read_model", + (std::shared_ptr(ov::runtime::Core::*)(const std::string&, const ov::runtime::Tensor&) const) & + ov::runtime::Core::read_model, + py::arg("model"), + py::arg("weights")); + + cls.def( + "read_model", + [](ov::runtime::Core& self, py::object model, py::object weights) { + return self.read_model(py::str(model), py::str(weights)); + }, + py::arg("model"), + py::arg("weights") = ""); + + cls.def( + "import_model", + (ov::runtime::ExecutableNetwork(ov::runtime::Core::*)(std::istream&, const std::string&, const ConfigMap&)) & + ov::runtime::Core::import_model, + py::arg("model_file"), + py::arg("device_name"), + py::arg("config") = py::none()); + + cls.def( + "get_config", + [](ov::runtime::Core& self, const std::string& device_name, const std::string& name) -> py::handle { + return Common::parse_parameter(self.get_config(device_name, name)); + }, + py::arg("device_name"), + py::arg("name")); + + cls.def( + "get_metric", + [](ov::runtime::Core& self, const std::string device_name, const std::string name) -> py::handle { + return Common::parse_parameter(self.get_metric(device_name, name)); + }, + py::arg("device_name"), + py::arg("name")); + + cls.def("register_plugin", &ov::runtime::Core::register_plugin, py::arg("plugin_name"), py::arg("device_name")); + + cls.def("register_plugins", &ov::runtime::Core::register_plugins, py::arg("xml_config_file")); + + cls.def("unload_plugin", &ov::runtime::Core::unload_plugin, py::arg("device_name")); + + cls.def( + "query_model", + (ov::runtime::SupportedOpsMap( + ov::runtime::Core::*)(const std::shared_ptr&, const std::string&, const ConfigMap&)) & + ov::runtime::Core::query_model, + py::arg("model"), + py::arg("device_name"), + py::arg("config") = py::dict()); + + cls.def_property_readonly("available_devices", &ov::runtime::Core::get_available_devices); +} diff --git a/runtime/bindings/python/src/pyopenvino/core/ie_core.hpp b/runtime/bindings/python/src/pyopenvino/core/core.hpp similarity index 100% rename from runtime/bindings/python/src/pyopenvino/core/ie_core.hpp rename to runtime/bindings/python/src/pyopenvino/core/core.hpp diff --git a/runtime/bindings/python/src/pyopenvino/core/executable_network.cpp b/runtime/bindings/python/src/pyopenvino/core/executable_network.cpp new file mode 100644 index 00000000000000..82817b68484f74 --- /dev/null +++ b/runtime/bindings/python/src/pyopenvino/core/executable_network.cpp @@ -0,0 +1,76 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 + +#include "openvino/runtime/executable_network.hpp" + +#include + +#include "common.hpp" +#include "pyopenvino/core/containers.hpp" +#include "pyopenvino/core/ie_infer_request.hpp" +#include "pyopenvino/core/ie_input_info.hpp" + +namespace py = pybind11; + +void regclass_ExecutableNetwork(py::module m) { + py::class_> cls( + m, + "ExecutableNetwork"); + + cls.def("create_infer_request", &ov::runtime::ExecutableNetwork::create_infer_request); + + // cls.def("infer_new_request", [](ov::runtime::ExecutableNetwork& self, const py::dict& inputs) { + // TODO: implment after https://github.com/openvinotoolkit/openvino/pull/7962 + // will be merged as a seperate ticket + // }); + + cls.def("export_model", &ov::runtime::ExecutableNetwork::export_model, py::arg("network_model")); + + cls.def( + "get_config", + [](ov::runtime::ExecutableNetwork& self, const std::string& name) -> py::handle { + return Common::parse_parameter(self.get_config(name)); + }, + py::arg("name")); + + cls.def( + "get_metric", + [](ov::runtime::ExecutableNetwork& self, const std::string& name) -> py::handle { + return Common::parse_parameter(self.get_metric(name)); + }, + py::arg("name")); + + cls.def("get_runtime_function", &ov::runtime::ExecutableNetwork::get_runtime_function); + + cls.def_property_readonly("inputs", &ov::runtime::ExecutableNetwork::inputs); + + cls.def("input", + (ov::Output(ov::runtime::ExecutableNetwork::*)() const) & + ov::runtime::ExecutableNetwork::input); + + cls.def("input", + (ov::Output(ov::runtime::ExecutableNetwork::*)(size_t) const) & + ov::runtime::ExecutableNetwork::input, + py::arg("i")); + + cls.def("input", + (ov::Output(ov::runtime::ExecutableNetwork::*)(const std::string&) const) & + ov::runtime::ExecutableNetwork::input, + py::arg("tensor_name")); + + cls.def_property_readonly("outputs", &ov::runtime::ExecutableNetwork::outputs); + + cls.def("output", + (ov::Output(ov::runtime::ExecutableNetwork::*)() const) & + ov::runtime::ExecutableNetwork::output); + + cls.def("output", + (ov::Output(ov::runtime::ExecutableNetwork::*)(size_t) const) & + ov::runtime::ExecutableNetwork::output, + py::arg("i")); + + cls.def("output", + (ov::Output(ov::runtime::ExecutableNetwork::*)(const std::string&) const) & + ov::runtime::ExecutableNetwork::output, + py::arg("tensor_name")); +} diff --git a/runtime/bindings/python/src/pyopenvino/core/ie_executable_network.hpp b/runtime/bindings/python/src/pyopenvino/core/executable_network.hpp similarity index 100% rename from runtime/bindings/python/src/pyopenvino/core/ie_executable_network.hpp rename to runtime/bindings/python/src/pyopenvino/core/executable_network.hpp diff --git a/runtime/bindings/python/src/pyopenvino/core/ie_core.cpp b/runtime/bindings/python/src/pyopenvino/core/ie_core.cpp deleted file mode 100644 index 9d37bfb00f7fe3..00000000000000 --- a/runtime/bindings/python/src/pyopenvino/core/ie_core.cpp +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "pyopenvino/core/ie_core.hpp" - -#include - -#include - -#include "common.hpp" - -namespace py = pybind11; - -std::string to_string(py::handle handle) { - auto encodedString = PyUnicode_AsUTF8String(handle.ptr()); - return PyBytes_AsString(encodedString); -} - -void regclass_Core(py::module m) { - py::class_> cls(m, "Core"); - cls.def(py::init()); - cls.def(py::init()); - - cls.def( - "set_config", - [](InferenceEngine::Core& self, const py::dict& config, const std::string& device_name) { - std::map config_map; - for (auto item : config) { - config_map[to_string(item.first)] = to_string(item.second); - } - self.SetConfig(config_map, device_name); - }, - py::arg("config"), - py::arg("device_name")); - - cls.def( - "load_network", - [](InferenceEngine::Core& self, - const InferenceEngine::CNNNetwork& network, - const std::string& device_name, - const std::map& config) { - return self.LoadNetwork(network, device_name, config); - }, - py::arg("network"), - py::arg("device_name"), - py::arg("config") = py::dict()); - - cls.def( - "add_extension", - [](InferenceEngine::Core& self, const std::string& extension_path, const std::string& device_name) { - auto extension_ptr = InferenceEngine::make_so_pointer(extension_path); - auto extension = std::dynamic_pointer_cast(extension_ptr); - self.AddExtension(extension, device_name); - }, - py::arg("extension_path"), - py::arg("device_name")); - - cls.def( - "get_versions", - [](InferenceEngine::Core& self, const std::string& device_name) { - return self.GetVersions(device_name); - }, - py::arg("device_name")); - - cls.def( - "read_network", - [](InferenceEngine::Core& self, py::bytes model, py::bytes weights) { - InferenceEngine::MemoryBlob::Ptr weights_blob; - if (weights) { - std::string weights_bytes = weights; - uint8_t* bin = (uint8_t*)weights_bytes.c_str(); - size_t bin_size = weights_bytes.length(); - InferenceEngine::TensorDesc tensorDesc(InferenceEngine::Precision::U8, - {bin_size}, - InferenceEngine::Layout::C); - weights_blob = InferenceEngine::make_shared_blob(tensorDesc); - weights_blob->allocate(); - memcpy(weights_blob->rwmap().as(), bin, bin_size); - } - return self.ReadNetwork(model, weights_blob); - }, - py::arg("model"), - py::arg("weights")); - - cls.def( - "read_network", - [](InferenceEngine::Core& self, const std::string& model, const std::string& weights) { - return self.ReadNetwork(model, weights); - }, - py::arg("model"), - py::arg("weights") = ""); - - cls.def( - "read_network", - [](InferenceEngine::Core& self, const std::string& model, py::handle blob) { - return self.ReadNetwork(model, Common::cast_to_blob(blob)); - }, - py::arg("model"), - py::arg("blob")); - - cls.def( - "read_network", - [](InferenceEngine::Core& self, py::object model, py::object weights) { - return self.ReadNetwork(py::str(model), py::str(weights)); - }, - py::arg("model"), - py::arg("weights") = ""); - - cls.def( - "import_network", - [](InferenceEngine::Core& self, - const std::string& model_file, - const std::string& device_name, - const std::map& config) { - return self.ImportNetwork(model_file, device_name, config); - }, - py::arg("model_file"), - py::arg("device_name"), - py::arg("config") = py::none()); - - cls.def( - "get_config", - [](InferenceEngine::Core& self, const std::string& device_name, const std::string& config_name) -> py::handle { - return Common::parse_parameter(self.GetConfig(device_name, config_name)); - }, - py::arg("device_name"), - py::arg("config_name")); - - cls.def( - "get_metric", - [](InferenceEngine::Core& self, std::string device_name, std::string metric_name) -> py::handle { - return Common::parse_parameter(self.GetMetric(device_name, metric_name)); - }, - py::arg("device_name"), - py::arg("metric_name")); - - cls.def("register_plugin", - &InferenceEngine::Core::RegisterPlugin, - py::arg("plugin_name"), - py::arg("device_name") = py::str()); - - cls.def("register_plugins", &InferenceEngine::Core::RegisterPlugins); - - cls.def("unregister_plugin", &InferenceEngine::Core::UnregisterPlugin, py::arg("device_name")); - - cls.def( - "query_network", - [](InferenceEngine::Core& self, - const InferenceEngine::CNNNetwork& network, - const std::string& device_name, - const std::map& config) { - return self.QueryNetwork(network, device_name, config).supportedLayersMap; - }, - py::arg("network"), - py::arg("device_name"), - py::arg("config") = py::dict()); - - cls.def_property_readonly("available_devices", &InferenceEngine::Core::GetAvailableDevices); -} diff --git a/runtime/bindings/python/src/pyopenvino/core/ie_executable_network.cpp b/runtime/bindings/python/src/pyopenvino/core/ie_executable_network.cpp deleted file mode 100644 index 37199110f09e68..00000000000000 --- a/runtime/bindings/python/src/pyopenvino/core/ie_executable_network.cpp +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (C) 2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 - -#include "pyopenvino/core/ie_executable_network.hpp" - -#include -#include - -#include "common.hpp" -#include "pyopenvino/core/containers.hpp" -#include "pyopenvino/core/ie_infer_request.hpp" -#include "pyopenvino/core/ie_input_info.hpp" - -namespace py = pybind11; - -void regclass_ExecutableNetwork(py::module m) { - py::class_> cls( - m, - "ExecutableNetwork"); - - cls.def("create_infer_request", [](InferenceEngine::ExecutableNetwork& self) { - auto request = InferRequestWrapper(self.CreateInferRequest()); - // Get Inputs and Outputs info from executable network - request._inputsInfo = self.GetInputsInfo(); - request._outputsInfo = self.GetOutputsInfo(); - // request.user_callback_defined = false; - return request; - }); - - cls.def( - "_infer", - [](InferenceEngine::ExecutableNetwork& self, const py::dict& inputs) { - // Create temporary InferRequest - auto request = self.CreateInferRequest(); - // Update inputs if there are any - if (!inputs.empty()) { - Common::set_request_blobs(request, inputs); //, self.GetInputsInfo()); - } - // Call Infer function - request.Infer(); - // Get output Blobs and return - Containers::PyResults results; - InferenceEngine::ConstOutputsDataMap outputsInfo = self.GetOutputsInfo(); - for (auto& out : outputsInfo) { - results[out.first] = request.GetBlob(out.first); - } - return results; - }, - py::arg("inputs")); - - cls.def("get_exec_graph_info", &InferenceEngine::ExecutableNetwork::GetExecGraphInfo); - - cls.def( - "export", - [](InferenceEngine::ExecutableNetwork& self, const std::string& modelFileName) { - self.Export(modelFileName); - }, - py::arg("model_file")); - - cls.def( - "get_config", - [](InferenceEngine::ExecutableNetwork& self, const std::string& config_name) -> py::handle { - return Common::parse_parameter(self.GetConfig(config_name)); - }, - py::arg("config_name")); - - cls.def( - "get_metric", - [](InferenceEngine::ExecutableNetwork& self, const std::string& metric_name) -> py::handle { - return Common::parse_parameter(self.GetMetric(metric_name)); - }, - py::arg("metric_name")); - - cls.def_property_readonly("input_info", [](InferenceEngine::ExecutableNetwork& self) { - Containers::PyConstInputsDataMap inputs; - const InferenceEngine::ConstInputsDataMap& inputsInfo = self.GetInputsInfo(); - for (const auto& in : inputsInfo) { - inputs[in.first] = in.second; - } - return inputs; - }); - - cls.def_property_readonly("output_info", [](InferenceEngine::ExecutableNetwork& self) { - Containers::PyOutputsDataMap outputs; - InferenceEngine::ConstOutputsDataMap outputsInfo = self.GetOutputsInfo(); - for (auto& out : outputsInfo) { - outputs[out.first] = out.second; - } - return outputs; - }); -} diff --git a/runtime/bindings/python/src/pyopenvino/core/ie_infer_request.cpp b/runtime/bindings/python/src/pyopenvino/core/ie_infer_request.cpp index f45ddd6a5cd73d..52d250f92ee7b7 100644 --- a/runtime/bindings/python/src/pyopenvino/core/ie_infer_request.cpp +++ b/runtime/bindings/python/src/pyopenvino/core/ie_infer_request.cpp @@ -10,7 +10,7 @@ #include "pyopenvino/core/common.hpp" #include "pyopenvino/core/containers.hpp" -#include "pyopenvino/core/ie_executable_network.hpp" +#include "pyopenvino/core/executable_network.hpp" #include "pyopenvino/core/ie_preprocess_info.hpp" namespace py = pybind11; diff --git a/runtime/bindings/python/src/pyopenvino/core/ie_version.cpp b/runtime/bindings/python/src/pyopenvino/core/ie_version.cpp index 158cda68ceaaef..45b2b0ed6b30c9 100644 --- a/runtime/bindings/python/src/pyopenvino/core/ie_version.cpp +++ b/runtime/bindings/python/src/pyopenvino/core/ie_version.cpp @@ -2,24 +2,23 @@ // SPDX-License-Identifier: Apache-2.0 // -#include "pyopenvino/core/ie_version.hpp" +#include -#include +#include "openvino/core/version.hpp" namespace py = pybind11; void regclass_Version(py::module m) { - py::class_ cls(m, "Version"); + py::class_ cls(m, "Version"); - cls.def_readonly("build_number", &InferenceEngine::Version::buildNumber); - cls.def_readonly("description", &InferenceEngine::Version::description); - cls.def_readwrite("api_version", &InferenceEngine::Version::apiVersion); + cls.def_readonly("build_number", &ov::Version::buildNumber); + cls.def_readonly("description", &ov::Version::description); - cls.def_property_readonly("major", [](InferenceEngine::Version& self) { - return IE_VERSION_MAJOR; + cls.def_property_readonly("major", [](ov::Version& self) { + return OPENVINO_VERSION_MAJOR; }); - cls.def_property_readonly("minor", [](InferenceEngine::Version& self) { - return IE_VERSION_MINOR; + cls.def_property_readonly("minor", [](ov::Version& self) { + return OPENVINO_VERSION_MINOR; }); -} \ No newline at end of file +} diff --git a/runtime/bindings/python/src/pyopenvino/graph/node_output.cpp b/runtime/bindings/python/src/pyopenvino/graph/node_output.cpp index 56ac60e3ba9f64..8d1cfcec5bb7d0 100644 --- a/runtime/bindings/python/src/pyopenvino/graph/node_output.cpp +++ b/runtime/bindings/python/src/pyopenvino/graph/node_output.cpp @@ -11,68 +11,5 @@ namespace py = pybind11; -void regclass_graph_Output(py::module m) { - py::class_, std::shared_ptr>> output(m, "Output", py::dynamic_attr()); - output.doc() = "openvino.impl.Output wraps ov::Output"; - - output.def("get_node", - &ov::Output::get_node, - R"( - Get node referenced by this output handle. - - Returns - ---------- - get_node : Node - Node object referenced by this output handle. - )"); - output.def("get_index", - &ov::Output::get_index, - R"( - The index of the output referred to by this output handle. - - Returns - ---------- - get_index : int - Index value as integer. - )"); - output.def("get_element_type", - &ov::Output::get_element_type, - R"( - The element type of the output referred to by this output handle. - - Returns - ---------- - get_element_type : Type - Type of the output. - )"); - output.def("get_shape", - &ov::Output::get_shape, - R"( - The shape of the output referred to by this output handle. - - Returns - ---------- - get_shape : Shape - Shape of the output. - )"); - output.def("get_partial_shape", - &ov::Output::get_partial_shape, - R"( - The partial shape of the output referred to by this output handle. - - Returns - ---------- - get_partial_shape : PartialShape - PartialShape of the output. - )"); - output.def("get_target_inputs", - &ov::Output::get_target_inputs, - R"( - A set containing handles for all inputs targeted by the output - referenced by this output handle. - Returns - ---------- - get_target_inputs : Set[Input] - Set of Inputs. - )"); -} +template void regclass_graph_Output(py::module m, std::string typestring); +template void regclass_graph_Output(py::module m, std::string typestring); diff --git a/runtime/bindings/python/src/pyopenvino/graph/node_output.hpp b/runtime/bindings/python/src/pyopenvino/graph/node_output.hpp index 9934c628b2e098..a88722ebc18448 100644 --- a/runtime/bindings/python/src/pyopenvino/graph/node_output.hpp +++ b/runtime/bindings/python/src/pyopenvino/graph/node_output.hpp @@ -5,7 +5,80 @@ #pragma once #include +#include + +#include "openvino/core/node_output.hpp" namespace py = pybind11; -void regclass_graph_Output(py::module m); +template +void regclass_graph_Output(py::module m, std::string typestring) +{ + auto pyclass_name = py::detail::c_str((typestring + std::string("Output"))); + auto docs = py::detail::c_str((std::string("openvino.impl.") + typestring + std::string("Output wraps ov::Output<") + typestring + std::string(" ov::Node >"))); + py::class_, std::shared_ptr>> output(m, + pyclass_name, + py::dynamic_attr()); + output.doc() = docs; + + output.def("get_node", + &ov::Output::get_node, + R"( + Get node referenced by this output handle. + + Returns + ---------- + get_node : Node or const Node + Node object referenced by this output handle. + )"); + output.def("get_index", + &ov::Output::get_index, + R"( + The index of the output referred to by this output handle. + + Returns + ---------- + get_index : int + Index value as integer. + )"); + output.def("get_element_type", + &ov::Output::get_element_type, + R"( + The element type of the output referred to by this output handle. + + Returns + ---------- + get_element_type : Type + Type of the output. + )"); + output.def("get_shape", + &ov::Output::get_shape, + R"( + The shape of the output referred to by this output handle. + + Returns + ---------- + get_shape : Shape + Shape of the output. + )"); + output.def("get_partial_shape", + &ov::Output::get_partial_shape, + R"( + The partial shape of the output referred to by this output handle. + + Returns + ---------- + get_partial_shape : PartialShape + PartialShape of the output. + )"); + output.def("get_target_inputs", + &ov::Output::get_target_inputs, + R"( + A set containing handles for all inputs targeted by the output + referenced by this output handle. + Returns + ---------- + get_target_inputs : Set[Input] + Set of Inputs. + )"); +} diff --git a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp index 7611244a38b410..8384e753134ad9 100644 --- a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp +++ b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp @@ -21,10 +21,10 @@ # include "pyopenvino/graph/onnx_import/onnx_import.hpp" #endif #include "pyopenvino/core/containers.hpp" +#include "pyopenvino/core/core.hpp" +#include "pyopenvino/core/executable_network.hpp" #include "pyopenvino/core/ie_blob.hpp" -#include "pyopenvino/core/ie_core.hpp" #include "pyopenvino/core/ie_data.hpp" -#include "pyopenvino/core/ie_executable_network.hpp" #include "pyopenvino/core/ie_infer_queue.hpp" #include "pyopenvino/core/ie_infer_request.hpp" #include "pyopenvino/core/ie_input_info.hpp" @@ -92,7 +92,6 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_graph_PartialShape(m); regclass_graph_Node(m); regclass_graph_Input(m); - regclass_graph_Output(m); regclass_graph_NodeFactory(m); regclass_graph_Strides(m); regclass_graph_CoordinateDiff(m); @@ -113,6 +112,8 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_graph_Variant(m); regclass_graph_VariantWrapper(m, std::string("String")); regclass_graph_VariantWrapper(m, std::string("Int")); + regclass_graph_Output(m, std::string("")); + regclass_graph_Output(m, std::string("Const")); regclass_Core(m); regclass_IENetwork(m); diff --git a/runtime/bindings/python/tests/__init__.py b/runtime/bindings/python/tests/__init__.py index 2ed2779a0de11a..d6efec455e9e5f 100644 --- a/runtime/bindings/python/tests/__init__.py +++ b/runtime/bindings/python/tests/__init__.py @@ -146,3 +146,4 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): xfail_issue_63138 = xfail_test(reason="Missing ONNX Shape-15 support") xfail_issue_63643 = xfail_test(reason="RuntimeError: Unsupported operation of type: Convolution name") xfail_issue_54663 = xfail_test(reason="Disabled until MaxPool-8 is supported on CPU") +xfail_issue_68212 = xfail_test(reason="Unsupported reading model with bytes streams") diff --git a/runtime/bindings/python/tests/runtime.py b/runtime/bindings/python/tests/runtime.py index cc5c49620a6c5e..2b79cf3af5af50 100644 --- a/runtime/bindings/python/tests/runtime.py +++ b/runtime/bindings/python/tests/runtime.py @@ -32,22 +32,6 @@ def get_runtime(): return runtime() -def _convert_inputs(cnn_network: IENetwork) -> None: - """WA converts unsupported input images formats.""" - precision_map = { - "FP64": "FP32", - "I64": "I32", - "U32": "I32", - } - - for cnn_input in cnn_network.input_info: - try: - _precision = precision_map[cnn_network.input_info[cnn_input].precision] - cnn_network.input_info[cnn_input].precision = _precision - except KeyError: - pass - - def _convert_val(val): """WA converts unsupported input values.""" if type(val) is np.ndarray: @@ -60,18 +44,6 @@ def _convert_val(val): return np.array(val, dtype=np.float32) -def apply_ng_type(output: DataPtr, ng_type: Type): - ng_ie_supported_type_map = { - Type.boolean.get_type_name(): "BOOL", - Type.f32.get_type_name(): "FP32", - Type.i8.get_type_name(): "I8", - Type.i32.get_type_name(): "I32", - Type.u8.get_type_name(): "U8", - } - if ng_type.get_type_name() in ng_ie_supported_type_map: - output.precision = ng_ie_supported_type_map[ng_type.get_type_name()] - - class Runtime(object): """Represents an nGraph runtime environment.""" @@ -166,21 +138,15 @@ def __call__(self, *input_values: NumericData) -> List[NumericData]: param_names = [param.friendly_name for param in self.parameters] if self.network_cache.get(str(input_shapes)) is None: - cnn_network = IENetwork(self.function) + function = self.function if self.function.is_dynamic(): - cnn_network.reshape(dict(zip(param_names, input_shapes))) + function.reshape(dict(zip(param_names, input_shapes))) # Convert unsupported inputs of the network - _convert_inputs(cnn_network) - self.network_cache[str(input_shapes)] = cnn_network + self.network_cache[str(input_shapes)] = function else: - cnn_network = self.network_cache[str(input_shapes)] - - # set output blobs precission based on nG results - for ng_result in self.results: - ie_out_name = self._get_ie_output_blob_name(cnn_network.outputs, ng_result) - apply_ng_type(cnn_network.outputs[ie_out_name], ng_result.get_output_element_type(0)) + function = self.network_cache[str(input_shapes)] - executable_network = self.runtime.backend.load_network(cnn_network, self.runtime.backend_name) + executable_network = self.runtime.backend.compile_model(function, self.runtime.backend_name) for parameter, input in zip(self.parameters, input_values): parameter_shape = parameter.get_output_partial_shape(0) diff --git a/runtime/bindings/python/tests/test_inference_engine/test_core.py b/runtime/bindings/python/tests/test_inference_engine/test_core.py index 59ed993278c8aa..7035d5e4dcea75 100644 --- a/runtime/bindings/python/tests/test_inference_engine/test_core.py +++ b/runtime/bindings/python/tests/test_inference_engine/test_core.py @@ -8,7 +8,7 @@ from pathlib import Path import openvino.opset8 as ov -from openvino import Core, IENetwork, ExecutableNetwork, blob_from_file +from openvino import Core, IENetwork, ExecutableNetwork, tensor_from_file from openvino.impl import Function, Shape, Type from openvino.impl.op import Parameter from openvino import TensorDesc, Blob @@ -51,7 +51,7 @@ def test_ie_core_class(): ie_core = Core() ie_core.set_config({}, device_name="CPU") - executable_network = ie_core.load_network(cnn_network, "CPU", {}) + executable_network = ie_core.compile_model(cnn_network, "CPU", {}) td = TensorDesc("FP32", input_shape, "NCHW") @@ -72,96 +72,80 @@ def test_ie_core_class(): assert np.allclose(result, expected_output) -def test_load_network(device): +def test_compile_model(device): ie = Core() - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - exec_net = ie.load_network(net, device) + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) assert isinstance(exec_net, ExecutableNetwork) -def test_read_network(): +def test_read_model(): ie_core = Core() - net = ie_core.read_network(model=test_net_xml, weights=test_net_bin) - assert isinstance(net, IENetwork) + func = ie_core.read_model(model=test_net_xml, weights=test_net_bin) + assert isinstance(func, Function) - net = ie_core.read_network(model=test_net_xml) - assert isinstance(net, IENetwork) + func = ie_core.read_model(model=test_net_xml) + assert isinstance(func, Function) -def test_read_network_from_blob(): +def test_read_model_from_blob(): ie_core = Core() model = open(test_net_xml).read() - blob = blob_from_file(test_net_bin) - net = ie_core.read_network(model=model, blob=blob) - assert isinstance(net, IENetwork) + tensor = tensor_from_file(test_net_bin) + func = ie_core.read_model(model=model, weights=tensor) + assert isinstance(func, Function) -def test_read_network_from_blob_valid(): +def test_read_model_as_path(): ie_core = Core() - model = open(test_net_xml).read() - blob = blob_from_file(test_net_bin) - net = ie_core.read_network(model=model, blob=blob) - ref_net = ie_core.read_network(model=test_net_xml, weights=test_net_bin) - assert net.name == ref_net.name - assert net.batch_size == ref_net.batch_size - ii_net = net.input_info - ii_net2 = ref_net.input_info - o_net = net.outputs - o_net2 = ref_net.outputs - assert ii_net.keys() == ii_net2.keys() - assert o_net.keys() == o_net2.keys() - - -def test_read_network_as_path(): - ie_core = Core() - net = ie_core.read_network(model=Path(test_net_xml), weights=Path(test_net_bin)) - assert isinstance(net, IENetwork) + func = ie_core.read_model(model=Path(test_net_xml), weights=Path(test_net_bin)) + assert isinstance(func, Function) - net = ie_core.read_network(model=test_net_xml, weights=Path(test_net_bin)) - assert isinstance(net, IENetwork) + func = ie_core.read_model(model=test_net_xml, weights=Path(test_net_bin)) + assert isinstance(func, Function) - net = ie_core.read_network(model=Path(test_net_xml)) - assert isinstance(net, IENetwork) + func = ie_core.read_model(model=Path(test_net_xml)) + assert isinstance(func, Function) -def test_read_network_from_onnx(): +def test_read_model_from_onnx(): ie_core = Core() - net = ie_core.read_network(model=test_net_onnx) - assert isinstance(net, IENetwork) + func = ie_core.read_model(model=test_net_onnx) + assert isinstance(func, Function) -def test_read_network_from_onnx_as_path(): +def test_read_model_from_onnx_as_path(): ie_core = Core() - net = ie_core.read_network(model=Path(test_net_onnx)) - assert isinstance(net, IENetwork) - + func = ie_core.read_model(model=Path(test_net_onnx)) + assert isinstance(func, Function) +@pytest.mark.xfail("68212") def test_read_net_from_buffer(): ie_core = Core() with open(test_net_bin, "rb") as f: bin = f.read() with open(model_path()[0], "rb") as f: xml = f.read() - net = ie_core.read_network(model=xml, weights=bin) - assert isinstance(net, IENetwork) - + func = ie_core.read_model(model=xml, weights=bin) + assert isinstance(func, IENetwork) +@pytest.mark.xfail("68212") def test_net_from_buffer_valid(): ie_core = Core() with open(test_net_bin, "rb") as f: bin = f.read() with open(model_path()[0], "rb") as f: xml = f.read() - net = ie_core.read_network(model=xml, weights=bin) - ref_net = ie_core.read_network(model=test_net_xml, weights=test_net_bin) - assert net.name == ref_net.name - assert net.batch_size == ref_net.batch_size - ii_net = net.input_info - ii_net2 = ref_net.input_info - o_net = net.outputs - o_net2 = ref_net.outputs - assert ii_net.keys() == ii_net2.keys() - assert o_net.keys() == o_net2.keys() + func = ie_core.read_model(model=xml, weights=bin) + ref_func = ie_core.read_model(model=test_net_xml, weights=test_net_bin) + assert func.name == func.name + assert func.batch_size == ref_func.batch_size + ii_func = func.input_info + ii_func2 = ref_func.input_info + o_func = func.outputs + o_func2 = ref_func.outputs + assert ii_func.keys() == ii_func2.keys() + assert o_func.keys() == o_func2.keys() def test_get_version(device): @@ -230,15 +214,14 @@ def test_get_metric_str(): f"metric must be string but {type(param)} is returned" -def test_query_network(device): +def test_query_model(device): ie = Core() - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - query_res = ie.query_network(network=net, device_name=device) - func_net = net.get_function() - ops_net = func_net.get_ordered_ops() - ops_net_names = [op.friendly_name for op in ops_net] - assert [key for key in query_res.keys() if key not in ops_net_names] == [], \ - "Not all network layers present in query_network results" + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + query_res = ie.query_model(model=func, device_name=device) + ops_func = func.get_ordered_ops() + ops_func_names = [op.friendly_name for op in ops_func] + assert [key for key in query_res.keys() if key not in ops_func_names] == [], \ + "Not all network layers present in query_model results" assert next(iter(set(query_res.values()))) == device, "Wrong device for some layers" @@ -246,8 +229,8 @@ def test_query_network(device): def test_register_plugin(): ie = Core() ie.register_plugin("MKLDNNPlugin", "BLA") - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - exec_net = ie.load_network(net, "BLA") + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, "BLA") assert isinstance(exec_net, ExecutableNetwork), \ "Cannot load the network to the registered plugin with name 'BLA'" @@ -262,8 +245,8 @@ def test_register_plugins(): elif platform == "win32": ie.register_plugins(plugins_win_xml) - net = ie.read_network(model=test_net_xml, weights=test_net_bin) - exec_net = ie.load_network(net, "CUSTOM") + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, "CUSTOM") assert isinstance(exec_net, ExecutableNetwork), "Cannot load the network to " \ "the registered plugin with name 'CUSTOM' " \ diff --git a/runtime/bindings/python/tests/test_inference_engine/test_executable_network.py b/runtime/bindings/python/tests/test_inference_engine/test_executable_network.py new file mode 100644 index 00000000000000..79ebaf7b5056c3 --- /dev/null +++ b/runtime/bindings/python/tests/test_inference_engine/test_executable_network.py @@ -0,0 +1,229 @@ +import numpy as np +import os +import pytest +import warnings +import time +from pathlib import Path + +from ..conftest import model_path, image_path +from openvino.impl import Function, ConstOutput, Shape, PartialShape + +from openvino import Core + +is_myriad = os.environ.get("TEST_DEVICE") == "MYRIAD" +path_to_image = image_path() +test_net_xml, test_net_bin = model_path(is_myriad) + +def image_path(): + path_to_repo = os.environ["DATA_PATH"] + path_to_img = os.path.join(path_to_repo, "validation_set", "224x224", "dog.bmp") + return path_to_img + + +def model_path(is_myriad=False): + path_to_repo = os.environ["MODELS_PATH"] + if not is_myriad: + test_xml = os.path.join(path_to_repo, "models", "test_model", "test_model_fp32.xml") + test_bin = os.path.join(path_to_repo, "models", "test_model", "test_model_fp32.bin") + else: + test_xml = os.path.join(path_to_repo, "models", "test_model", "test_model_fp16.xml") + test_bin = os.path.join(path_to_repo, "models", "test_model", "test_model_fp16.bin") + return (test_xml, test_bin) + + +def read_image(): + import cv2 + n, c, h, w = (1, 3, 32, 32) + image = cv2.imread(path_to_img) + if image is None: + raise FileNotFoundError("Input image not found") + + image = cv2.resize(image, (h, w)) / 255 + image = image.transpose((2, 0, 1)).astype(np.float32) + image = image.reshape((n, c, h, w)) + return image + + +def test_get_runtime_function(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + runtime_func = exec_net.get_runtime_function() + assert isinstance(runtime_func, Function) + + +def test_get_input_i(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + input = exec_net.input(0); + input_node = input.get_node() + name = input_node.friendly_name + assert isinstance(input, ConstOutput) + assert name == "data" + + +def test_get_input_tensor_name(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + input = exec_net.input("data"); + input_node = input.get_node() + name = input_node.friendly_name + assert isinstance(input, ConstOutput) + assert name == "data" + + +def test_get_input(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + input = exec_net.input(); + input_node = input.get_node() + name = input_node.friendly_name + assert isinstance(input, ConstOutput) + assert name == "data" + + +def test_get_output_i(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + output = exec_net.output(0); + assert isinstance(output, ConstOutput) + + +def test_get_output(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + output = exec_net.output(); + output_node = output.get_node() + assert isinstance(output, ConstOutput) + + +def test_input_set_friendly_name(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + input = exec_net.input("data"); + input_node = input.get_node() + input_node.set_friendly_name("input_1") + name = input_node.friendly_name + assert isinstance(input, ConstOutput) + assert name == "input_1" + + +def test_output_set_friendly_name(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + output = exec_net.output(0); + output_node = output.get_node() + output_node.set_friendly_name("output_1") + name = output_node.friendly_name + assert isinstance(output, ConstOutput) + assert name == "output_1" + + +def test_outputs(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + outputs = exec_net.outputs + assert isinstance(outputs, list) + assert len(outputs) == 1 + + +def test_outputs_items(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + outputs = exec_net.outputs + assert isinstance(outputs[0], ConstOutput) + + +def test_output_type(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + output = exec_net.output(0) + output_type = output.get_element_type().get_type_name() + assert output_type == "f32" + +def test_output_shape(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + output = exec_net.output(0) + expected_shape = Shape([1, 10]) + assert str(output.get_shape()) == str(expected_shape) + + +def test_input_get_index(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + input = exec_net.input(0) + expected_idx = 0 + assert input.get_index() == expected_idx + + +def test_input_get_index(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + input = exec_net.input(0) + expected_partial_shape = PartialShape([1, 3, 32 ,32]) + assert input.get_partial_shape() == expected_partial_shape + + +def test_inputs(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + inputs = exec_net.inputs + assert isinstance(inputs, list) + assert len(inputs) == 1 + + +def test_inputs_items(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + inputs = exec_net.inputs + assert isinstance(inputs[0], ConstOutput) + + +def test_inputs_get_friendly_name(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + inputs = exec_net.inputs + input_0 = inputs[0] + node = input_0.get_node() + name = node.friendly_name + assert name == "data" + + +def test_inputs_set_friendly_name(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + inputs = exec_net.inputs + input_0 = inputs[0] + node = input_0.get_node() + node.set_friendly_name("input_0") + name = node.friendly_name + assert name == "input_0" + + +def test_inputs_docs(device): + ie = Core() + func = ie.read_model(model=test_net_xml, weights=test_net_bin) + exec_net = ie.compile_model(func, device) + inputs = exec_net.inputs + input_0 = inputs[0] + exptected_string = "openvino.impl.ConstOutput wraps ov::Output" + assert input_0.__doc__ == exptected_string + diff --git a/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py b/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py index 518a11cb37dead..50fbf1db853920 100644 --- a/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py +++ b/runtime/bindings/python/tests/test_inference_engine/test_infer_request.py @@ -15,9 +15,9 @@ def test_get_perf_counts(device): ie_core = Core() - net = ie_core.read_network(test_net_xml, test_net_bin) + func = ie_core.read_model(test_net_xml, test_net_bin) ie_core.set_config({"PERF_COUNT": "YES"}, device) - exec_net = ie_core.load_network(net, device) + exec_net = ie_core.compile_model(func, device) img = read_image() request = exec_net.create_infer_request() td = TensorDesc("FP32", [1, 3, 32, 32], "NCHW") @@ -39,10 +39,10 @@ def test_get_perf_counts(device): def test_set_batch_size(device): ie_core = Core() ie_core.set_config({"DYN_BATCH_ENABLED": "YES"}, device) - net = ie_core.read_network(test_net_xml, test_net_bin) - net.batch_size = 10 + func = ie_core.read_model(test_net_xml, test_net_bin) + func.batch_size = 10 data = np.ones(shape=net.input_info["data"].input_data.shape) - exec_net = ie_core.load_network(net, device) + exec_net = ie_core.compile_model(net, device) data[0] = read_image()[0] request = exec_net.create_infer_request() request.set_batch(1) @@ -60,38 +60,38 @@ def test_set_batch_size(device): @pytest.mark.skip(reason="Fix") def test_set_zero_batch_size(device): ie_core = Core() - net = ie_core.read_network(test_net_xml, test_net_bin) - exec_net = ie_core.load_network(net, device) + func = ie_core.read_model(test_net_xml, test_net_bin) + exec_net = ie_core.compile_model(func, device) request = exec_net.create_infer_request() with pytest.raises(ValueError) as e: request.set_batch(0) assert "Batch size should be positive integer number but 0 specified" in str(e.value) del exec_net del ie_core - del net + del func @pytest.mark.skip(reason="Fix") def test_set_negative_batch_size(device): ie_core = Core() - net = ie_core.read_network(test_net_xml, test_net_bin) - exec_net = ie_core.load_network(net, device) + func = ie_core.read_model(test_net_xml, test_net_bin) + exec_net = ie_core.compile_model(func, device) request = exec_net.create_infer_request() with pytest.raises(ValueError) as e: request.set_batch(-1) assert "Batch size should be positive integer number but -1 specified" in str(e.value) del exec_net del ie_core - del net + del func def test_blob_setter(device): ie_core = Core() - net = ie_core.read_network(test_net_xml, test_net_bin) - exec_net_1 = ie_core.load_network(network=net, device_name=device) + func = ie_core.read_model(test_net_xml, test_net_bin) + exec_net_1 = ie_core.compile_model(network=func, device_name=device) - net.input_info["data"].layout = "NHWC" - exec_net_2 = ie_core.load_network(network=net, device_name=device) + func.input_info["data"].layout = "NHWC" + exec_net_2 = ie_core.compile_model(network=func, device_name=device) img = read_image() @@ -114,8 +114,8 @@ def test_blob_setter(device): def test_cancel(device): ie_core = Core() - net = ie_core.read_network(test_net_xml, test_net_bin) - exec_net = ie_core.load_network(net, device) + func = ie_core.read_model(test_net_xml, test_net_bin) + exec_net = ie_core.compile_model(func, device) img = read_image() td = TensorDesc("FP32", [1, 3, 32, 32], "NCHW") input_blob = Blob(td, img) diff --git a/runtime/bindings/python/tests/test_onnx/test_onnx_external_data.py b/runtime/bindings/python/tests/test_onnx/test_onnx_external_data.py index cbeb316c79ad6c..8fd4fb89ca582d 100644 --- a/runtime/bindings/python/tests/test_onnx/test_onnx_external_data.py +++ b/runtime/bindings/python/tests/test_onnx/test_onnx_external_data.py @@ -12,9 +12,7 @@ def test_import_onnx_with_external_data(): model_path = os.path.join(os.path.dirname(__file__), "models/external_data.onnx") ie = Core() - network = ie.read_network(model=model_path) - - ng_function = network.get_function() + func = ie.read_model(model=model_path) dtype = np.float32 value_a = np.array([1.0, 3.0, 5.0], dtype=dtype) @@ -22,6 +20,6 @@ def test_import_onnx_with_external_data(): # third input [5.0, 1.0, 3.0] read from external file runtime = get_runtime() - computation = runtime.computation(ng_function) + computation = runtime.computation(func) result = computation(value_a, value_b) assert np.allclose(result, np.array([3.0, 3.0, 3.0], dtype=dtype)) diff --git a/runtime/bindings/python/tests/test_onnx/test_onnx_import.py b/runtime/bindings/python/tests/test_onnx/test_onnx_import.py index 2886ff592f3ef3..7c59a9462c989d 100644 --- a/runtime/bindings/python/tests/test_onnx/test_onnx_import.py +++ b/runtime/bindings/python/tests/test_onnx/test_onnx_import.py @@ -15,9 +15,7 @@ def test_import_onnx_function(): model_path = os.path.join(os.path.dirname(__file__), "models/add_abc.onnx") ie = Core() - network = ie.read_network(model=model_path) - - ng_function = network.get_function() + func = ie.read_model(model=model_path) dtype = np.float32 value_a = np.array([1.0], dtype=dtype) @@ -25,7 +23,7 @@ def test_import_onnx_function(): value_c = np.array([3.0], dtype=dtype) runtime = get_runtime() - computation = runtime.computation(ng_function) + computation = runtime.computation(func) result = computation(value_a, value_b, value_c) assert np.allclose(result, np.array([6], dtype=dtype)) diff --git a/runtime/bindings/python/tests/test_onnx/utils/onnx_helpers.py b/runtime/bindings/python/tests/test_onnx/utils/onnx_helpers.py index 53c5487d31476f..7c7c7f2c7d8654 100644 --- a/runtime/bindings/python/tests/test_onnx/utils/onnx_helpers.py +++ b/runtime/bindings/python/tests/test_onnx/utils/onnx_helpers.py @@ -5,7 +5,7 @@ import onnx from onnx.mapping import NP_TYPE_TO_TENSOR_TYPE -from openvino import Core, Blob, TensorDesc +from openvino import Core, Tensor from openvino.impl import Function @@ -21,9 +21,7 @@ def np_dtype_to_tensor_type(data_type: np.dtype) -> int: def import_onnx_model(model: onnx.ModelProto) -> Function: onnx.checker.check_model(model) model_byte_string = model.SerializeToString() - ie = Core() - ie_network = ie.read_network(bytes(model_byte_string), Blob(TensorDesc("U8", [], "C"))) + func = ie.read_model(bytes(model_byte_string), Tensor(np.array([], dtype=np.uint8))) - ng_function = ie_network.get_function() - return ng_function + return func