From ca6f620100e5bd6eeedbb77a37637bee27b105cb Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 12:27:03 +0300 Subject: [PATCH 01/10] move frontend folder to pyopenvino --- .../{compatibility/pyngraph => pyopenvino}/frontend/frontend.cpp | 0 .../{compatibility/pyngraph => pyopenvino}/frontend/frontend.hpp | 0 .../pyngraph => pyopenvino}/frontend/frontend_manager.cpp | 0 .../pyngraph => pyopenvino}/frontend/frontend_manager.hpp | 0 .../pyngraph => pyopenvino}/frontend/inputmodel.cpp | 0 .../pyngraph => pyopenvino}/frontend/inputmodel.hpp | 0 .../src/{compatibility/pyngraph => pyopenvino}/frontend/place.cpp | 0 .../src/{compatibility/pyngraph => pyopenvino}/frontend/place.hpp | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend.cpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend.hpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend_manager.cpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/frontend_manager.hpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/inputmodel.cpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/inputmodel.hpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/place.cpp (100%) rename runtime/bindings/python/src/{compatibility/pyngraph => pyopenvino}/frontend/place.hpp (100%) diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend.cpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend.cpp rename to runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend.hpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend.hpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend.hpp rename to runtime/bindings/python/src/pyopenvino/frontend/frontend.hpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.cpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.cpp rename to runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.hpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/frontend_manager.hpp rename to runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.cpp b/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.cpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.cpp rename to runtime/bindings/python/src/pyopenvino/frontend/inputmodel.cpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.hpp b/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.hpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/inputmodel.hpp rename to runtime/bindings/python/src/pyopenvino/frontend/inputmodel.hpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/place.cpp b/runtime/bindings/python/src/pyopenvino/frontend/place.cpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/place.cpp rename to runtime/bindings/python/src/pyopenvino/frontend/place.cpp diff --git a/runtime/bindings/python/src/compatibility/pyngraph/frontend/place.hpp b/runtime/bindings/python/src/pyopenvino/frontend/place.hpp similarity index 100% rename from runtime/bindings/python/src/compatibility/pyngraph/frontend/place.hpp rename to runtime/bindings/python/src/pyopenvino/frontend/place.hpp From 2082b1013e28d6e1fc476fce8dd89b57cdf6c862 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 13:04:20 +0300 Subject: [PATCH 02/10] rename includes and add compile options --- .../src/compatibility/pyngraph/pyngraph.cpp | 13 ----------- .../python/src/pyopenvino/CMakeLists.txt | 22 ++++++++++++++++++- .../src/pyopenvino/frontend/frontend.cpp | 2 +- .../python/src/pyopenvino/frontend/place.cpp | 2 +- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/runtime/bindings/python/src/compatibility/pyngraph/pyngraph.cpp b/runtime/bindings/python/src/compatibility/pyngraph/pyngraph.cpp index 75097734960955..5cfac29c3ac32f 100644 --- a/runtime/bindings/python/src/compatibility/pyngraph/pyngraph.cpp +++ b/runtime/bindings/python/src/compatibility/pyngraph/pyngraph.cpp @@ -18,10 +18,6 @@ #endif #include "pyngraph/dimension.hpp" #include "pyngraph/discrete_type_info.hpp" -#include "pyngraph/frontend/frontend.hpp" -#include "pyngraph/frontend/frontend_manager.hpp" -#include "pyngraph/frontend/inputmodel.hpp" -#include "pyngraph/frontend/place.hpp" #include "pyngraph/ops/constant.hpp" #include "pyngraph/ops/parameter.hpp" #include "pyngraph/ops/result.hpp" @@ -45,15 +41,6 @@ PYBIND11_MODULE(_pyngraph, m) { regclass_pyngraph_Shape(m); regclass_pyngraph_PartialShape(m); regclass_pyngraph_Node(m); - regclass_pyngraph_Place(m); - regclass_pyngraph_InitializationFailureFrontEnd(m); - regclass_pyngraph_GeneralFailureFrontEnd(m); - regclass_pyngraph_OpConversionFailureFrontEnd(m); - regclass_pyngraph_OpValidationFailureFrontEnd(m); - regclass_pyngraph_NotImplementedFailureFrontEnd(m); - regclass_pyngraph_FrontEndManager(m); - regclass_pyngraph_FrontEnd(m); - regclass_pyngraph_InputModel(m); regclass_pyngraph_Input(m); regclass_pyngraph_Output(m); regclass_pyngraph_NodeFactory(m); diff --git a/runtime/bindings/python/src/pyopenvino/CMakeLists.txt b/runtime/bindings/python/src/pyopenvino/CMakeLists.txt index 305a5687c0fee4..986176e49b35d0 100644 --- a/runtime/bindings/python/src/pyopenvino/CMakeLists.txt +++ b/runtime/bindings/python/src/pyopenvino/CMakeLists.txt @@ -24,6 +24,26 @@ if(OpenVINO_SOURCE_DIR) set(CMAKE_PDB_OUTPUT_DIRECTORY ${PYTHON_BRIDGE_OUTPUT_DIRECTORY}) endif() +# compile options + +if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # disable warning: This operator was deprecated and will be removed with v0 operation. + add_compile_options(/wd4996) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + add_compile_options(-Wno-deprecated-register -Wno-range-loop-analysis) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + add_link_options(-stdlib=libc++) + add_compile_options(-Wno-unused-value -Wno-range-loop-analysis) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + # WA for GCC 7.5 "PYBIND11_NOINLINE inline" warning + add_compile_options(-Wno-error=attributes) +endif() + +if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # for proper fix need to update pybind to version which does not use PyEval_InitThreads() + add_compile_options(-Wno-deprecated-declarations -Wno-undef) +endif() + # create target file(GLOB_RECURSE SOURCES *.cpp) @@ -31,7 +51,7 @@ file(GLOB_RECURSE SOURCES *.cpp) pybind11_add_module(${PROJECT_NAME} MODULE ${SOURCES}) target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") -target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime) +target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime openvino::frontend::manager) # perform copy if(OpenVINO_SOURCE_DIR) diff --git a/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp index db3dccfc44b63f..ab8edf72fbccdb 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp @@ -9,7 +9,7 @@ #include "frontend_manager.hpp" #include "frontend_manager/frontend_exceptions.hpp" #include "frontend_manager/frontend_manager.hpp" -#include "pyngraph/function.hpp" +#include "pyopenvino/graph/function.hpp" namespace py = pybind11; diff --git a/runtime/bindings/python/src/pyopenvino/frontend/place.cpp b/runtime/bindings/python/src/pyopenvino/frontend/place.cpp index 5414d74529f9b5..05b810141294c1 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/place.cpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/place.cpp @@ -9,7 +9,7 @@ #include "frontend_manager.hpp" #include "frontend_manager/frontend_exceptions.hpp" #include "frontend_manager/frontend_manager.hpp" -#include "pyngraph/function.hpp" +#include "pyopenvino/graph/function.hpp" namespace py = pybind11; From eb0f7afd8e03533d2df4721253381baf8a0cf305 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 13:41:23 +0300 Subject: [PATCH 03/10] include frontend to pyopenvino --- .../python/src/pyopenvino/frontend/frontend.cpp | 2 +- .../python/src/pyopenvino/frontend/frontend.hpp | 2 +- .../src/pyopenvino/frontend/frontend_manager.cpp | 12 ++++++------ .../src/pyopenvino/frontend/frontend_manager.hpp | 12 ++++++------ .../python/src/pyopenvino/frontend/inputmodel.cpp | 2 +- .../python/src/pyopenvino/frontend/inputmodel.hpp | 2 +- .../python/src/pyopenvino/frontend/place.cpp | 2 +- .../python/src/pyopenvino/frontend/place.hpp | 2 +- .../bindings/python/src/pyopenvino/pyopenvino.cpp | 13 +++++++++++++ 9 files changed, 31 insertions(+), 18 deletions(-) diff --git a/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp index ab8edf72fbccdb..45d33276729abb 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/frontend.cpp @@ -13,7 +13,7 @@ namespace py = pybind11; -void regclass_pyngraph_FrontEnd(py::module m) { +void regclass_frontend_FrontEnd(py::module m) { py::class_> fem(m, "FrontEnd", py::dynamic_attr(), diff --git a/runtime/bindings/python/src/pyopenvino/frontend/frontend.hpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend.hpp index de28e950bb5c97..50b5b252d8c60d 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/frontend.hpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/frontend.hpp @@ -8,4 +8,4 @@ namespace py = pybind11; -void regclass_pyngraph_FrontEnd(py::module m); +void regclass_frontend_FrontEnd(py::module m); diff --git a/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp index 250e80e69e5d74..f9bf6976430695 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.cpp @@ -13,7 +13,7 @@ namespace py = pybind11; -void regclass_pyngraph_FrontEndManager(py::module m) { +void regclass_frontend_FrontEndManager(py::module m) { py::class_> fem( m, "FrontEndManager", @@ -85,7 +85,7 @@ void regclass_pyngraph_FrontEndManager(py::module m) { }); } -void regclass_pyngraph_GeneralFailureFrontEnd(py::module m) { +void regclass_frontend_GeneralFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "GeneralFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -97,7 +97,7 @@ void regclass_pyngraph_GeneralFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_OpValidationFailureFrontEnd(py::module m) { +void regclass_frontend_OpValidationFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "OpValidationFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -109,7 +109,7 @@ void regclass_pyngraph_OpValidationFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_OpConversionFailureFrontEnd(py::module m) { +void regclass_frontend_OpConversionFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "OpConversionFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -121,7 +121,7 @@ void regclass_pyngraph_OpConversionFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_InitializationFailureFrontEnd(py::module m) { +void regclass_frontend_InitializationFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "InitializationFailure"); py::register_exception_translator([](std::exception_ptr p) { try { @@ -133,7 +133,7 @@ void regclass_pyngraph_InitializationFailureFrontEnd(py::module m) { }); } -void regclass_pyngraph_NotImplementedFailureFrontEnd(py::module m) { +void regclass_frontend_NotImplementedFailureFrontEnd(py::module m) { static py::exception exc(std::move(m), "NotImplementedFailure"); py::register_exception_translator([](std::exception_ptr p) { try { diff --git a/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp b/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp index 969ddd6859ab88..aa2e0a16a047e0 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/frontend_manager.hpp @@ -8,10 +8,10 @@ namespace py = pybind11; -void regclass_pyngraph_FrontEndManager(py::module m); -void regclass_pyngraph_NotImplementedFailureFrontEnd(py::module m); -void regclass_pyngraph_InitializationFailureFrontEnd(py::module m); -void regclass_pyngraph_OpConversionFailureFrontEnd(py::module m); -void regclass_pyngraph_OpValidationFailureFrontEnd(py::module m); -void regclass_pyngraph_GeneralFailureFrontEnd(py::module m); +void regclass_frontend_FrontEndManager(py::module m); +void regclass_frontend_NotImplementedFailureFrontEnd(py::module m); +void regclass_frontend_InitializationFailureFrontEnd(py::module m); +void regclass_frontend_OpConversionFailureFrontEnd(py::module m); +void regclass_frontend_OpValidationFailureFrontEnd(py::module m); +void regclass_frontend_GeneralFailureFrontEnd(py::module m); diff --git a/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.cpp b/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.cpp index a8cb5f30557b69..9728ca00a05bb8 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.cpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.cpp @@ -11,7 +11,7 @@ namespace py = pybind11; -void regclass_pyngraph_InputModel(py::module m) { +void regclass_frontend_InputModel(py::module m) { py::class_> im(m, "InputModel", py::dynamic_attr(), diff --git a/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.hpp b/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.hpp index e95179c4a8cddc..6759aaff4997cd 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.hpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/inputmodel.hpp @@ -8,4 +8,4 @@ namespace py = pybind11; -void regclass_pyngraph_InputModel(py::module m); +void regclass_frontend_InputModel(py::module m); diff --git a/runtime/bindings/python/src/pyopenvino/frontend/place.cpp b/runtime/bindings/python/src/pyopenvino/frontend/place.cpp index 05b810141294c1..42ec3212f3081e 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/place.cpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/place.cpp @@ -13,7 +13,7 @@ namespace py = pybind11; -void regclass_pyngraph_Place(py::module m) { +void regclass_frontend_Place(py::module m) { py::class_> place(m, "Place", py::dynamic_attr(), diff --git a/runtime/bindings/python/src/pyopenvino/frontend/place.hpp b/runtime/bindings/python/src/pyopenvino/frontend/place.hpp index 1a52e21f028e24..68c371de095827 100644 --- a/runtime/bindings/python/src/pyopenvino/frontend/place.hpp +++ b/runtime/bindings/python/src/pyopenvino/frontend/place.hpp @@ -8,4 +8,4 @@ namespace py = pybind11; -void regclass_pyngraph_Place(py::module m); +void regclass_frontend_Place(py::module m); diff --git a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp index 816c3ebfa09081..5ad264aca2f15b 100644 --- a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp +++ b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp @@ -47,6 +47,10 @@ #include "pyopenvino/graph/types/regmodule_graph_types.hpp" #include "pyopenvino/graph/util.hpp" #include "pyopenvino/graph/variant.hpp" +#include "pyopenvino/frontend/frontend.hpp" +#include "pyopenvino/frontend/frontend_manager.hpp" +#include "pyopenvino/frontend/inputmodel.hpp" +#include "pyopenvino/frontend/place.hpp" namespace py = pybind11; @@ -88,6 +92,15 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_graph_Shape(m); regclass_graph_PartialShape(m); regclass_graph_Node(m); + regclass_frontend_Place(m); + regclass_frontend_InitializationFailureFrontEnd(m); + regclass_frontend_GeneralFailureFrontEnd(m); + regclass_frontend_OpConversionFailureFrontEnd(m); + regclass_frontend_OpValidationFailureFrontEnd(m); + regclass_frontend_NotImplementedFailureFrontEnd(m); + regclass_frontend_FrontEndManager(m); + regclass_frontend_FrontEnd(m); + regclass_frontend_InputModel(m); regclass_graph_Input(m); regclass_graph_Output(m); regclass_graph_NodeFactory(m); From fedb115c0e784c765715e8e66ecc4814c200392a Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 15:19:24 +0300 Subject: [PATCH 04/10] move __init__.py --- .../src/compatibility/ngraph/__init__.py | 9 -------- .../compatibility/ngraph/frontend/__init__.py | 22 ------------------- .../python/src/openvino/frontend/__init__.py | 22 +++++++++++++++++++ 3 files changed, 22 insertions(+), 31 deletions(-) delete mode 100644 runtime/bindings/python/src/compatibility/ngraph/frontend/__init__.py create mode 100644 runtime/bindings/python/src/openvino/frontend/__init__.py diff --git a/runtime/bindings/python/src/compatibility/ngraph/__init__.py b/runtime/bindings/python/src/compatibility/ngraph/__init__.py index 8b12a3c7ff9d82..fac0ae9a628677 100644 --- a/runtime/bindings/python/src/compatibility/ngraph/__init__.py +++ b/runtime/bindings/python/src/compatibility/ngraph/__init__.py @@ -15,15 +15,6 @@ from ngraph.impl import Function from ngraph.impl import Node from ngraph.impl import PartialShape -from ngraph.frontend import FrontEnd -from ngraph.frontend import FrontEndManager -from ngraph.frontend import GeneralFailure -from ngraph.frontend import NotImplementedFailure -from ngraph.frontend import InitializationFailure -from ngraph.frontend import InputModel -from ngraph.frontend import OpConversionFailure -from ngraph.frontend import OpValidationFailure -from ngraph.frontend import Place from ngraph.helpers import function_from_cnn from ngraph.helpers import function_to_cnn from ngraph.helpers import partial_shape_from_data diff --git a/runtime/bindings/python/src/compatibility/ngraph/frontend/__init__.py b/runtime/bindings/python/src/compatibility/ngraph/frontend/__init__.py deleted file mode 100644 index 72bd47445afd92..00000000000000 --- a/runtime/bindings/python/src/compatibility/ngraph/frontend/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 - -""" -Package: ngraph -Low level wrappers for the FrontEnd c++ api. -""" - -# flake8: noqa - -# main classes -from _pyngraph import FrontEndManager -from _pyngraph import FrontEnd -from _pyngraph import InputModel -from _pyngraph import Place - -# exceptions -from _pyngraph import NotImplementedFailure -from _pyngraph import InitializationFailure -from _pyngraph import OpConversionFailure -from _pyngraph import OpValidationFailure -from _pyngraph import GeneralFailure diff --git a/runtime/bindings/python/src/openvino/frontend/__init__.py b/runtime/bindings/python/src/openvino/frontend/__init__.py new file mode 100644 index 00000000000000..cf983342257e53 --- /dev/null +++ b/runtime/bindings/python/src/openvino/frontend/__init__.py @@ -0,0 +1,22 @@ +# Copyright (C) 2018-2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +""" +Package: ngraph +Low level wrappers for the FrontEnd c++ api. +""" + +# flake8: noqa + +# main classes +from pyopenvino import FrontEndManager +from pyopenvino import FrontEnd +from pyopenvino import InputModel +from pyopenvino import Place + +# exceptions +from pyopenvino import NotImplementedFailure +from pyopenvino import InitializationFailure +from pyopenvino import OpConversionFailure +from pyopenvino import OpValidationFailure +from pyopenvino import GeneralFailure From 4b69dee197c95ce87283e11201920705cf9ef2a5 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 16:11:45 +0300 Subject: [PATCH 05/10] move tests --- .../python/src/openvino/frontend/__init__.py | 18 +++++++++--------- .../python/src/pyopenvino/pyopenvino.cpp | 19 ++++++++++--------- .../test_frontend/test_frontend_onnx.py | 4 ++-- .../test_frontend_onnx_editor.py | 4 ++-- .../test_frontend/test_frontendmanager.py | 6 +++--- 5 files changed, 26 insertions(+), 25 deletions(-) rename runtime/bindings/python/{tests_compatibility => tests}/test_frontend/test_frontend_onnx.py (97%) rename runtime/bindings/python/{tests_compatibility => tests}/test_frontend/test_frontend_onnx_editor.py (99%) rename runtime/bindings/python/{tests_compatibility => tests}/test_frontend/test_frontendmanager.py (99%) diff --git a/runtime/bindings/python/src/openvino/frontend/__init__.py b/runtime/bindings/python/src/openvino/frontend/__init__.py index cf983342257e53..a73361b076722f 100644 --- a/runtime/bindings/python/src/openvino/frontend/__init__.py +++ b/runtime/bindings/python/src/openvino/frontend/__init__.py @@ -9,14 +9,14 @@ # flake8: noqa # main classes -from pyopenvino import FrontEndManager -from pyopenvino import FrontEnd -from pyopenvino import InputModel -from pyopenvino import Place +from openvino.pyopenvino import FrontEndManager +from openvino.pyopenvino import FrontEnd +from openvino.pyopenvino import InputModel +from openvino.pyopenvino import Place # exceptions -from pyopenvino import NotImplementedFailure -from pyopenvino import InitializationFailure -from pyopenvino import OpConversionFailure -from pyopenvino import OpValidationFailure -from pyopenvino import GeneralFailure +from openvino.pyopenvino import NotImplementedFailure +from openvino.pyopenvino import InitializationFailure +from openvino.pyopenvino import OpConversionFailure +from openvino.pyopenvino import OpValidationFailure +from openvino.pyopenvino import GeneralFailure diff --git a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp index 5ad264aca2f15b..e83ed365ba57c7 100644 --- a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp +++ b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp @@ -92,15 +92,6 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_graph_Shape(m); regclass_graph_PartialShape(m); regclass_graph_Node(m); - regclass_frontend_Place(m); - regclass_frontend_InitializationFailureFrontEnd(m); - regclass_frontend_GeneralFailureFrontEnd(m); - regclass_frontend_OpConversionFailureFrontEnd(m); - regclass_frontend_OpValidationFailureFrontEnd(m); - regclass_frontend_NotImplementedFailureFrontEnd(m); - regclass_frontend_FrontEndManager(m); - regclass_frontend_FrontEnd(m); - regclass_frontend_InputModel(m); regclass_graph_Input(m); regclass_graph_Output(m); regclass_graph_NodeFactory(m); @@ -160,4 +151,14 @@ PYBIND11_MODULE(pyopenvino, m) { regclass_InputInfo(m); regclass_InferQueue(m); regclass_PreProcessInfo(m); + + regclass_frontend_Place(m); + regclass_frontend_InitializationFailureFrontEnd(m); + regclass_frontend_GeneralFailureFrontEnd(m); + regclass_frontend_OpConversionFailureFrontEnd(m); + regclass_frontend_OpValidationFailureFrontEnd(m); + regclass_frontend_NotImplementedFailureFrontEnd(m); + regclass_frontend_FrontEndManager(m); + regclass_frontend_FrontEnd(m); + regclass_frontend_InputModel(m); } diff --git a/runtime/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx.py b/runtime/bindings/python/tests/test_frontend/test_frontend_onnx.py similarity index 97% rename from runtime/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx.py rename to runtime/bindings/python/tests/test_frontend/test_frontend_onnx.py index 221a5aa3372cff..7c36999c9cdfe8 100644 --- a/runtime/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx.py +++ b/runtime/bindings/python/tests/test_frontend/test_frontend_onnx.py @@ -7,8 +7,8 @@ from onnx.helper import make_graph, make_model, make_tensor_value_info import pytest -from ngraph.frontend import FrontEndManager -from tests_compatibility.runtime import get_runtime +from openvino.frontend import FrontEndManager +from tests.runtime import get_runtime def create_onnx_model(): diff --git a/runtime/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx_editor.py b/runtime/bindings/python/tests/test_frontend/test_frontend_onnx_editor.py similarity index 99% rename from runtime/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx_editor.py rename to runtime/bindings/python/tests/test_frontend/test_frontend_onnx_editor.py index cd8bdabd3e5e3a..4a59c0172dc5eb 100644 --- a/runtime/bindings/python/tests_compatibility/test_frontend/test_frontend_onnx_editor.py +++ b/runtime/bindings/python/tests/test_frontend/test_frontend_onnx_editor.py @@ -5,8 +5,8 @@ import onnx import pytest from onnx.helper import make_graph, make_model, make_tensor_value_info -from ngraph import PartialShape -from ngraph.frontend import FrontEndManager +from openvino import PartialShape +from openvino.frontend import FrontEndManager # ------Test input model 1------ diff --git a/runtime/bindings/python/tests_compatibility/test_frontend/test_frontendmanager.py b/runtime/bindings/python/tests/test_frontend/test_frontendmanager.py similarity index 99% rename from runtime/bindings/python/tests_compatibility/test_frontend/test_frontendmanager.py rename to runtime/bindings/python/tests/test_frontend/test_frontendmanager.py index 8ecece7404a864..62084e6d35eac7 100644 --- a/runtime/bindings/python/tests_compatibility/test_frontend/test_frontendmanager.py +++ b/runtime/bindings/python/tests/test_frontend/test_frontendmanager.py @@ -3,9 +3,9 @@ import pickle -from ngraph import PartialShape -from ngraph.frontend import FrontEndManager, InitializationFailure -from ngraph.utils.types import get_element_type +from openvino import PartialShape +from openvino.frontend import FrontEndManager, InitializationFailure +from openvino.utils.types import get_element_type import numpy as np From 966f5526da7d29c9cc62337b997118e7a59414ba Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 16:22:11 +0300 Subject: [PATCH 06/10] remove mock from tests_compatibility --- .../mock_py_ngraph_frontend/CMakeLists.txt | 24 - .../mock_py_frontend.cpp | 25 - .../mock_py_frontend.hpp | 665 ------------------ .../mock/pyngraph_fe_mock_api/CMakeLists.txt | 20 - .../pyngraph_mock_frontend_api.cpp | 127 ---- 5 files changed, 861 deletions(-) delete mode 100644 runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt delete mode 100644 runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp delete mode 100644 runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp delete mode 100644 runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt delete mode 100644 runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp diff --git a/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt b/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt deleted file mode 100644 index ac793895ad1bcc..00000000000000 --- a/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_FE_NAME "mock_py_ngraph_frontend") - -file(GLOB_RECURSE LIBRARY_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -file(GLOB_RECURSE LIBRARY_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) - -source_group("src" FILES ${LIBRARY_SRC}) -source_group("include" FILES ${LIBRARY_HEADERS}) - -# Create shared library -add_library(${TARGET_FE_NAME} SHARED ${LIBRARY_SRC} ${LIBRARY_HEADERS}) - -target_include_directories(${TARGET_FE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - -target_link_libraries(${TARGET_FE_NAME} PRIVATE frontend_manager::static) - -add_clang_format_target(${TARGET_FE_NAME}_clang FOR_TARGETS ${TARGET_FE_NAME}) - -install(TARGETS ${TARGET_FE_NAME} - RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT tests_compatibility EXCLUDE_FROM_ALL - LIBRARY DESTINATION ${IE_CPACK_LIBRARY_PATH} COMPONENT tests_compatibility EXCLUDE_FROM_ALL) diff --git a/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp b/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp deleted file mode 100644 index dd760e262462a9..00000000000000 --- a/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include "mock_py_frontend.hpp" - -#include "frontend_manager/frontend_manager.hpp" -#include "frontend_manager/frontend_manager_defs.hpp" - -using namespace ngraph; -using namespace ngraph::frontend; - -extern "C" MOCK_API FrontEndVersion GetAPIVersion() { - return OV_FRONTEND_API_VERSION; -} - -extern "C" MOCK_API void* GetFrontEndData() { - FrontEndPluginInfo* res = new FrontEndPluginInfo(); - res->m_name = "mock_py"; - res->m_creator = []() { - return std::make_shared(); - }; - - return res; -} diff --git a/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp b/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp deleted file mode 100644 index 3143aa96fdabd7..00000000000000 --- a/runtime/bindings/python/tests_compatibility/mock/mock_py_ngraph_frontend/mock_py_frontend.hpp +++ /dev/null @@ -1,665 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#pragma once - -#include "frontend_manager/frontend_manager.hpp" -#include "frontend_manager/frontend_manager_defs.hpp" -#include "ngraph/visibility.hpp" - -// Defined if we are building the plugin DLL (instead of using it) -#ifdef mock_py_ngraph_frontend_EXPORTS -# define MOCK_API NGRAPH_HELPER_DLL_EXPORT -#else -# define MOCK_API NGRAPH_HELPER_DLL_IMPORT -#endif // mock1_ngraph_frontend_EXPORTS - -// OK to have 'using' in mock header - -using namespace ngraph; -using namespace ngraph::frontend; - -//////////////////////////////// - -struct MOCK_API PlaceStat { - int m_get_names = 0; - int m_get_consuming_operations = 0; - int m_get_target_tensor = 0; - int m_get_producing_operation = 0; - int m_get_producing_port = 0; - int m_get_input_port = 0; - int m_get_output_port = 0; - int m_get_consuming_ports = 0; - int m_is_input = 0; - int m_is_output = 0; - int m_is_equal = 0; - int m_is_equal_data = 0; - int m_get_source_tensor = 0; - - // Arguments tracking - std::string m_lastArgString; - int m_lastArgInt; - Place::Ptr m_lastArgPlace = nullptr; - - // Getters - int get_names() const { - return m_get_names; - } - int get_consuming_operations() const { - return m_get_consuming_operations; - } - int get_target_tensor() const { - return m_get_target_tensor; - } - int get_producing_operation() const { - return m_get_producing_operation; - } - int get_producing_port() const { - return m_get_producing_port; - } - int get_input_port() const { - return m_get_input_port; - } - int get_output_port() const { - return m_get_output_port; - } - int get_consuming_ports() const { - return m_get_consuming_ports; - } - int is_input() const { - return m_is_input; - } - int is_output() const { - return m_is_output; - } - int is_equal() const { - return m_is_equal; - } - int is_equal_data() const { - return m_is_equal_data; - } - int get_source_tensor() const { - return m_get_source_tensor; - } - - // Arguments getters - std::string get_lastArgString() const { - return m_lastArgString; - } - int get_lastArgInt() const { - return m_lastArgInt; - } - Place::Ptr get_lastArgPlace() const { - return m_lastArgPlace; - } -}; - -class MOCK_API PlaceMockPy : public Place { - mutable PlaceStat m_stat; - -public: - std::vector get_names() const override { - m_stat.m_get_names++; - return {}; - } - - std::vector get_consuming_operations() const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = ""; - return {std::make_shared()}; - } - - std::vector get_consuming_operations(int outputPortIndex) const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = ""; - return {std::make_shared()}; - } - - std::vector get_consuming_operations(const std::string& outputName) const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - std::vector get_consuming_operations(const std::string& outputName, - int outputPortIndex) const override { - m_stat.m_get_consuming_operations++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - Place::Ptr get_target_tensor() const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_target_tensor(int outputPortIndex) const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = outputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_target_tensor(const std::string& outputName) const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - Place::Ptr get_target_tensor(const std::string& outputName, int outputPortIndex) const override { - m_stat.m_get_target_tensor++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = outputName; - return {std::make_shared()}; - } - - Place::Ptr get_producing_operation() const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_producing_operation(int inputPortIndex) const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = inputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_producing_operation(const std::string& inputName) const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - Place::Ptr get_producing_operation(const std::string& inputName, int inputPortIndex) const override { - m_stat.m_get_producing_operation++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - Place::Ptr get_producing_port() const override { - m_stat.m_get_producing_port++; - return std::make_shared(); - } - - Place::Ptr get_input_port() const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_input_port(int inputPortIndex) const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = inputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_input_port(const std::string& inputName) const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = inputName; - return std::make_shared(); - } - - Place::Ptr get_input_port(const std::string& inputName, int inputPortIndex) const override { - m_stat.m_get_input_port++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = inputName; - return std::make_shared(); - } - - Place::Ptr get_output_port() const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = -1; - return std::make_shared(); - } - - Place::Ptr get_output_port(int outputPortIndex) const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = outputPortIndex; - return std::make_shared(); - } - - Place::Ptr get_output_port(const std::string& outputName) const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = outputName; - return std::make_shared(); - } - - Place::Ptr get_output_port(const std::string& outputName, int outputPortIndex) const override { - m_stat.m_get_output_port++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = outputName; - return std::make_shared(); - } - - std::vector get_consuming_ports() const override { - m_stat.m_get_consuming_ports++; - return {std::make_shared()}; - } - - bool is_input() const override { - m_stat.m_is_input++; - return false; - } - - bool is_output() const override { - m_stat.m_is_output++; - return false; - } - - bool is_equal(Ptr another) const override { - m_stat.m_is_equal++; - m_stat.m_lastArgPlace = another; - return false; - } - - bool is_equal_data(Ptr another) const override { - m_stat.m_is_equal_data++; - m_stat.m_lastArgPlace = another; - return false; - } - - Place::Ptr get_source_tensor(int inputPortIndex) const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = inputPortIndex; - return {std::make_shared()}; - } - - Place::Ptr get_source_tensor() const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = -1; - return {std::make_shared()}; - } - - Place::Ptr get_source_tensor(const std::string& inputName) const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = -1; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - Place::Ptr get_source_tensor(const std::string& inputName, int inputPortIndex) const override { - m_stat.m_get_source_tensor++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = inputName; - return {std::make_shared()}; - } - - //---------------Stat-------------------- - PlaceStat get_stat() const { - return m_stat; - } -}; - -//////////////////////////////// - -struct MOCK_API ModelStat { - int m_get_inputs = 0; - int m_get_outputs = 0; - int m_get_place_by_tensor_name = 0; - int m_get_place_by_operation_name = 0; - int m_get_place_by_operation_and_input_port = 0; - int m_get_place_by_operation_and_output_port = 0; - int m_set_name_for_tensor = 0; - int m_add_name_for_tensor = 0; - int m_set_name_for_operation = 0; - int m_free_name_for_tensor = 0; - int m_free_name_for_operation = 0; - int m_set_name_for_dimension = 0; - int m_cut_and_add_new_input = 0; - int m_cut_and_add_new_output = 0; - int m_add_output = 0; - int m_remove_output = 0; - int m_set_partial_shape = 0; - int m_get_partial_shape = 0; - int m_set_element_type = 0; - - int m_extract_subgraph = 0; - int m_override_all_inputs = 0; - int m_override_all_outputs = 0; - - // Arguments tracking - std::string m_lastArgString; - int m_lastArgInt; - Place::Ptr m_lastArgPlace = nullptr; - std::vector m_lastArgInputPlaces; - std::vector m_lastArgOutputPlaces; - ngraph::element::Type m_lastArgElementType; - ngraph::PartialShape m_lastArgPartialShape; - - // Getters - int get_inputs() const { - return m_get_inputs; - } - int get_outputs() const { - return m_get_outputs; - } - int extract_subgraph() const { - return m_extract_subgraph; - } - int override_all_inputs() const { - return m_override_all_inputs; - } - int override_all_outputs() const { - return m_override_all_outputs; - } - int get_place_by_tensor_name() const { - return m_get_place_by_tensor_name; - } - int get_place_by_operation_name() const { - return m_get_place_by_operation_name; - } - int get_place_by_operation_and_input_port() const { - return m_get_place_by_operation_and_input_port; - } - int get_place_by_operation_and_output_port() const { - return m_get_place_by_operation_and_output_port; - } - int set_name_for_tensor() const { - return m_set_name_for_tensor; - } - int add_name_for_tensor() const { - return m_add_name_for_tensor; - } - int set_name_for_operation() const { - return m_set_name_for_operation; - } - int free_name_for_tensor() const { - return m_free_name_for_tensor; - } - int free_name_for_operation() const { - return m_free_name_for_operation; - } - int set_name_for_dimension() const { - return m_set_name_for_dimension; - } - int cut_and_add_new_input() const { - return m_cut_and_add_new_input; - } - int cut_and_add_new_output() const { - return m_cut_and_add_new_output; - } - int add_output() const { - return m_add_output; - } - int remove_output() const { - return m_remove_output; - } - int set_partial_shape() const { - return m_set_partial_shape; - } - int get_partial_shape() const { - return m_get_partial_shape; - } - int set_element_type() const { - return m_set_element_type; - } - - // Arguments getters - std::string get_lastArgString() const { - return m_lastArgString; - } - int get_lastArgInt() const { - return m_lastArgInt; - } - Place::Ptr get_lastArgPlace() const { - return m_lastArgPlace; - } - std::vector get_lastArgInputPlaces() const { - return m_lastArgInputPlaces; - } - std::vector get_lastArgOutputPlaces() const { - return m_lastArgOutputPlaces; - } - ngraph::element::Type get_lastArgElementType() const { - return m_lastArgElementType; - } - ngraph::PartialShape get_lastArgPartialShape() const { - return m_lastArgPartialShape; - } -}; - -class MOCK_API InputModelMockPy : public InputModel { - mutable ModelStat m_stat; - -public: - std::vector get_inputs() const override { - m_stat.m_get_inputs++; - return {std::make_shared()}; - } - - std::vector get_outputs() const override { - m_stat.m_get_outputs++; - return {std::make_shared()}; - } - - Place::Ptr get_place_by_tensor_name(const std::string& tensorName) const override { - m_stat.m_get_place_by_tensor_name++; - m_stat.m_lastArgString = tensorName; - return std::make_shared(); - } - - Place::Ptr get_place_by_operation_name(const std::string& operationName) const override { - m_stat.m_get_place_by_operation_name++; - m_stat.m_lastArgString = operationName; - return std::make_shared(); - } - - Place::Ptr get_place_by_operation_name_and_input_port(const std::string& operationName, - int inputPortIndex) override { - m_stat.m_get_place_by_operation_and_input_port++; - m_stat.m_lastArgInt = inputPortIndex; - m_stat.m_lastArgString = operationName; - return std::make_shared(); - } - - Place::Ptr get_place_by_operation_name_and_output_port(const std::string& operationName, - int outputPortIndex) override { - m_stat.m_get_place_by_operation_and_output_port++; - m_stat.m_lastArgInt = outputPortIndex; - m_stat.m_lastArgString = operationName; - return std::make_shared(); - } - - void set_name_for_tensor(Place::Ptr tensor, const std::string& newName) override { - m_stat.m_set_name_for_tensor++; - m_stat.m_lastArgPlace = tensor; - m_stat.m_lastArgString = newName; - } - - void add_name_for_tensor(Place::Ptr tensor, const std::string& newName) override { - m_stat.m_add_name_for_tensor++; - m_stat.m_lastArgPlace = tensor; - m_stat.m_lastArgString = newName; - } - - void set_name_for_operation(Place::Ptr operation, const std::string& newName) override { - m_stat.m_set_name_for_operation++; - m_stat.m_lastArgPlace = operation; - m_stat.m_lastArgString = newName; - } - - void free_name_for_tensor(const std::string& name) override { - m_stat.m_free_name_for_tensor++; - m_stat.m_lastArgString = name; - } - - void free_name_for_operation(const std::string& name) override { - m_stat.m_free_name_for_operation++; - m_stat.m_lastArgString = name; - } - - void set_name_for_dimension(Place::Ptr place, size_t shapeDimIndex, const std::string& dimName) override { - m_stat.m_set_name_for_dimension++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgInt = static_cast(shapeDimIndex); - m_stat.m_lastArgString = dimName; - } - - void cut_and_add_new_input(Place::Ptr place, const std::string& newNameOptional) override { - m_stat.m_cut_and_add_new_input++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgString = newNameOptional; - } - - void cut_and_add_new_output(Place::Ptr place, const std::string& newNameOptional) override { - m_stat.m_cut_and_add_new_output++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgString = newNameOptional; - } - - Place::Ptr add_output(Place::Ptr place) override { - m_stat.m_add_output++; - m_stat.m_lastArgPlace = place; - return std::make_shared(); - } - - void remove_output(Place::Ptr place) override { - m_stat.m_remove_output++; - m_stat.m_lastArgPlace = place; - } - - void override_all_outputs(const std::vector& outputs) override { - m_stat.m_override_all_outputs++; - m_stat.m_lastArgOutputPlaces = outputs; - } - - void override_all_inputs(const std::vector& inputs) override { - m_stat.m_override_all_inputs++; - m_stat.m_lastArgInputPlaces = inputs; - } - - void extract_subgraph(const std::vector& inputs, const std::vector& outputs) override { - m_stat.m_extract_subgraph++; - m_stat.m_lastArgInputPlaces = inputs; - m_stat.m_lastArgOutputPlaces = outputs; - } - - // Setting tensor properties - void set_partial_shape(Place::Ptr place, const ngraph::PartialShape& shape) override { - m_stat.m_set_partial_shape++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgPartialShape = shape; - } - - ngraph::PartialShape get_partial_shape(Place::Ptr place) const override { - m_stat.m_get_partial_shape++; - m_stat.m_lastArgPlace = place; - return {}; - } - - void set_element_type(Place::Ptr place, const ngraph::element::Type& type) override { - m_stat.m_set_element_type++; - m_stat.m_lastArgPlace = place; - m_stat.m_lastArgElementType = type; - } - - //---------------Stat-------------------- - ModelStat get_stat() const { - return m_stat; - } -}; - -///////////////////////////////////////////////////////// - -struct MOCK_API FeStat { - std::vector m_load_paths; - int m_convert_model = 0; - int m_convert = 0; - int m_convert_partially = 0; - int m_decode = 0; - int m_normalize = 0; - int m_get_name = 0; - int m_supported = 0; - // Getters - std::vector load_paths() const { - return m_load_paths; - } - int convert_model() const { - return m_convert_model; - } - int convert() const { - return m_convert; - } - int convert_partially() const { - return m_convert_partially; - } - int decode() const { - return m_decode; - } - int normalize() const { - return m_normalize; - } - int get_name() const { - return m_get_name; - } - int supported() const { - return m_supported; - } -}; - -class MOCK_API FrontEndMockPy : public FrontEnd { - mutable FeStat m_stat; - -public: - FrontEndMockPy() {} - - InputModel::Ptr load_impl(const std::vector>& params) const override { - if (params.size() > 0 && ov::is_type>(params[0])) - m_stat.m_load_paths.push_back(ov::as_type_ptr>(params[0])->get()); - return std::make_shared(); - } - - bool supported_impl(const std::vector>& params) const override { - m_stat.m_supported++; - if (params.size() > 0 && ov::is_type>(params[0])) { - auto path = ov::as_type_ptr>(params[0])->get(); - if (path.find(".test_mock_py_mdl") != std::string::npos) { - return true; - } - } - return false; - } - - std::shared_ptr convert(InputModel::Ptr model) const override { - m_stat.m_convert_model++; - return std::make_shared(NodeVector{}, ParameterVector{}); - } - - void convert(std::shared_ptr func) const override { - m_stat.m_convert++; - } - - std::shared_ptr convert_partially(InputModel::Ptr model) const override { - m_stat.m_convert_partially++; - return std::make_shared(NodeVector{}, ParameterVector{}); - } - - std::shared_ptr decode(InputModel::Ptr model) const override { - m_stat.m_decode++; - return std::make_shared(NodeVector{}, ParameterVector{}); - } - - void normalize(std::shared_ptr function) const override { - m_stat.m_normalize++; - } - - std::string get_name() const override { - m_stat.m_get_name++; - return "mock_py"; - } - - FeStat get_stat() const { - return m_stat; - } -}; diff --git a/runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt b/runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt deleted file mode 100644 index 957ab59e0a07e9..00000000000000 --- a/runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/CMakeLists.txt +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2018-2021 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# - -set(TARGET_FE_NAME "mock_py_ngraph_frontend") -set(PYBIND_FE_NAME "pybind_mock_frontend") - -set(PYBIND_FE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/pyngraph_mock_frontend_api.cpp) - -source_group("src" FILES ${PYBIND_FE_SRC}) - -pybind11_add_module(${PYBIND_FE_NAME} MODULE ${PYBIND_FE_SRC}) - -target_link_libraries(${PYBIND_FE_NAME} PRIVATE ${TARGET_FE_NAME} frontend_manager::static) - -add_clang_format_target(${PYBIND_FE_NAME}_clang FOR_TARGETS ${PYBIND_FE_NAME}) - -install(TARGETS ${PYBIND_FE_NAME} - DESTINATION python/${PYTHON_VERSION} - COMPONENT tests_compatibility EXCLUDE_FROM_ALL) diff --git a/runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp b/runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp deleted file mode 100644 index 54e022b978fe63..00000000000000 --- a/runtime/bindings/python/tests_compatibility/mock/pyngraph_fe_mock_api/pyngraph_mock_frontend_api.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright (C) 2018-2021 Intel Corporation -// SPDX-License-Identifier: Apache-2.0 -// - -#include -#include - -#include "../mock_py_ngraph_frontend/mock_py_frontend.hpp" - -namespace py = pybind11; -using namespace ngraph; -using namespace ngraph::frontend; - -static void register_mock_frontend_stat(py::module m) { - m.def( - "get_fe_stat", - [](const std::shared_ptr& fe) { - std::shared_ptr ptr = std::dynamic_pointer_cast(fe); - if (ptr) { - auto stat = ptr->get_stat(); - return stat; - } - return FeStat(); - }, - py::arg("frontend")); - - py::class_ feStat(m, "FeStat", py::dynamic_attr()); - feStat.def_property_readonly("load_paths", &FeStat::load_paths); - feStat.def_property_readonly("convert_model", &FeStat::convert_model); - feStat.def_property_readonly("convert", &FeStat::convert); - feStat.def_property_readonly("convert_partially", &FeStat::convert_partially); - feStat.def_property_readonly("decode", &FeStat::decode); - feStat.def_property_readonly("normalize", &FeStat::normalize); - feStat.def_property_readonly("get_name", &FeStat::get_name); - feStat.def_property_readonly("supported", &FeStat::supported); -} - -static void register_mock_model_stat(py::module m) { - m.def( - "get_mdl_stat", - [](const std::shared_ptr& mdl) { - std::shared_ptr ptr = std::dynamic_pointer_cast(mdl); - if (ptr) { - auto stat = ptr->get_stat(); - return stat; - } - return ModelStat(); - }, - py::arg("model")); - - py::class_ mdlStat(m, "ModelStat", py::dynamic_attr()); - mdlStat.def_property_readonly("get_inputs", &ModelStat::get_inputs); - mdlStat.def_property_readonly("get_outputs", &ModelStat::get_outputs); - mdlStat.def_property_readonly("get_place_by_tensor_name", &ModelStat::get_place_by_tensor_name); - mdlStat.def_property_readonly("get_place_by_operation_name", &ModelStat::get_place_by_operation_name); - mdlStat.def_property_readonly("get_place_by_operation_and_input_port", - &ModelStat::get_place_by_operation_and_input_port); - mdlStat.def_property_readonly("get_place_by_operation_and_output_port", - &ModelStat::get_place_by_operation_and_output_port); - - mdlStat.def_property_readonly("set_name_for_tensor", &ModelStat::set_name_for_tensor); - mdlStat.def_property_readonly("add_name_for_tensor", &ModelStat::add_name_for_tensor); - mdlStat.def_property_readonly("set_name_for_operation", &ModelStat::set_name_for_operation); - mdlStat.def_property_readonly("free_name_for_tensor", &ModelStat::free_name_for_tensor); - mdlStat.def_property_readonly("free_name_for_operation", &ModelStat::free_name_for_operation); - mdlStat.def_property_readonly("set_name_for_dimension", &ModelStat::set_name_for_dimension); - mdlStat.def_property_readonly("cut_and_add_new_input", &ModelStat::cut_and_add_new_input); - mdlStat.def_property_readonly("cut_and_add_new_output", &ModelStat::cut_and_add_new_output); - mdlStat.def_property_readonly("add_output", &ModelStat::add_output); - mdlStat.def_property_readonly("remove_output", &ModelStat::remove_output); - mdlStat.def_property_readonly("set_partial_shape", &ModelStat::set_partial_shape); - mdlStat.def_property_readonly("get_partial_shape", &ModelStat::get_partial_shape); - mdlStat.def_property_readonly("set_element_type", &ModelStat::set_element_type); - mdlStat.def_property_readonly("extract_subgraph", &ModelStat::extract_subgraph); - mdlStat.def_property_readonly("override_all_inputs", &ModelStat::override_all_inputs); - mdlStat.def_property_readonly("override_all_outputs", &ModelStat::override_all_outputs); - - // Arguments tracking - mdlStat.def_property_readonly("lastArgString", &ModelStat::get_lastArgString); - mdlStat.def_property_readonly("lastArgInt", &ModelStat::get_lastArgInt); - mdlStat.def_property_readonly("lastArgPlace", &ModelStat::get_lastArgPlace); - mdlStat.def_property_readonly("lastArgInputPlaces", &ModelStat::get_lastArgInputPlaces); - mdlStat.def_property_readonly("lastArgOutputPlaces", &ModelStat::get_lastArgOutputPlaces); - mdlStat.def_property_readonly("lastArgElementType", &ModelStat::get_lastArgElementType); - mdlStat.def_property_readonly("lastArgPartialShape", &ModelStat::get_lastArgPartialShape); -} - -static void register_mock_place_stat(py::module m) { - m.def( - "get_place_stat", - [](const Place::Ptr& fe) { - std::shared_ptr ptr = std::dynamic_pointer_cast(fe); - if (ptr) { - auto stat = ptr->get_stat(); - return stat; - } - return PlaceStat(); - }, - py::arg("place")); - - py::class_ placeStat(m, "PlaceStat", py::dynamic_attr()); - - placeStat.def_property_readonly("lastArgString", &PlaceStat::get_lastArgString); - placeStat.def_property_readonly("lastArgInt", &PlaceStat::get_lastArgInt); - placeStat.def_property_readonly("lastArgPlace", &PlaceStat::get_lastArgPlace); - - placeStat.def_property_readonly("get_names", &PlaceStat::get_names); - placeStat.def_property_readonly("get_consuming_operations", &PlaceStat::get_consuming_operations); - placeStat.def_property_readonly("get_target_tensor", &PlaceStat::get_target_tensor); - placeStat.def_property_readonly("get_producing_operation", &PlaceStat::get_producing_operation); - placeStat.def_property_readonly("get_producing_port", &PlaceStat::get_producing_port); - placeStat.def_property_readonly("get_input_port", &PlaceStat::get_input_port); - placeStat.def_property_readonly("get_output_port", &PlaceStat::get_output_port); - placeStat.def_property_readonly("get_consuming_ports", &PlaceStat::get_consuming_ports); - placeStat.def_property_readonly("is_input", &PlaceStat::is_input); - placeStat.def_property_readonly("is_output", &PlaceStat::is_output); - placeStat.def_property_readonly("is_equal", &PlaceStat::is_equal); - placeStat.def_property_readonly("is_equal_data", &PlaceStat::is_equal_data); - placeStat.def_property_readonly("get_source_tensor", &PlaceStat::get_source_tensor); -} - -PYBIND11_MODULE(pybind_mock_frontend, m) { - m.doc() = "Mock frontend call counters for testing Pyngraph frontend bindings"; - register_mock_frontend_stat(m); - register_mock_model_stat(m); - register_mock_place_stat(m); -} From 323abd2cb4f157508361345ba5de9bc987790fa1 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Wed, 20 Oct 2021 16:35:38 +0300 Subject: [PATCH 07/10] rename import module --- model-optimizer/mo/main.py | 2 +- model-optimizer/mo/main_onnx.py | 2 +- model-optimizer/mo/main_paddle.py | 2 +- model-optimizer/mo/moc_frontend/extractor.py | 2 +- model-optimizer/mo/moc_frontend/pipeline.py | 2 +- model-optimizer/mo/utils/check_ie_bindings.py | 2 +- model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py | 2 +- .../unit_tests/mo/moc_frontend/moc_extractor_test_actual.py | 2 +- runtime/bindings/python/setup.py | 2 +- .../bindings/python/src/compatibility/pyngraph/CMakeLists.txt | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/model-optimizer/mo/main.py b/model-optimizer/mo/main.py index 60117df3baf9ef..d51520fe18f390 100644 --- a/model-optimizer/mo/main.py +++ b/model-optimizer/mo/main.py @@ -44,7 +44,7 @@ from mo.utils.versions_checker import check_requirements # pylint: disable=no-name-in-module # pylint: disable=no-name-in-module,import-error -from ngraph.frontend import FrontEndManager, FrontEnd +from openvino.frontend import FrontEndManager, FrontEnd def replace_ext(name: str, old: str, new: str): diff --git a/model-optimizer/mo/main_onnx.py b/model-optimizer/mo/main_onnx.py index 3f2fbb870bc295..51bcc5bcd28f85 100644 --- a/model-optimizer/mo/main_onnx.py +++ b/model-optimizer/mo/main_onnx.py @@ -7,6 +7,6 @@ if __name__ == "__main__": from mo.main import main - from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error + from openvino.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error sys.exit(main(get_onnx_cli_parser(), FrontEndManager(), 'onnx')) diff --git a/model-optimizer/mo/main_paddle.py b/model-optimizer/mo/main_paddle.py index a7d590ecfce4cc..963652a578c8ff 100644 --- a/model-optimizer/mo/main_paddle.py +++ b/model-optimizer/mo/main_paddle.py @@ -5,7 +5,7 @@ from mo.utils.cli_parser import get_all_cli_parser -from ngraph.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error +from openvino.frontend import FrontEndManager # pylint: disable=no-name-in-module,import-error if __name__ == "__main__": diff --git a/model-optimizer/mo/moc_frontend/extractor.py b/model-optimizer/mo/moc_frontend/extractor.py index b5ddd83b1fdef9..76bdc552eb74ea 100644 --- a/model-optimizer/mo/moc_frontend/extractor.py +++ b/model-optimizer/mo/moc_frontend/extractor.py @@ -6,7 +6,7 @@ from mo.front.extractor import raise_no_node, raise_node_name_collision from mo.utils.error import Error -from ngraph.frontend import InputModel # pylint: disable=no-name-in-module,import-error +from openvino.frontend import InputModel # pylint: disable=no-name-in-module,import-error import numpy as np diff --git a/model-optimizer/mo/moc_frontend/pipeline.py b/model-optimizer/mo/moc_frontend/pipeline.py index ca6924824af271..308e6bd69c4cc7 100644 --- a/model-optimizer/mo/moc_frontend/pipeline.py +++ b/model-optimizer/mo/moc_frontend/pipeline.py @@ -9,7 +9,7 @@ from mo.middle.passes.infer import validate_batch_in_shape from ngraph import Dimension, PartialShape # pylint: disable=no-name-in-module,import-error -from ngraph.frontend import FrontEnd, Place # pylint: disable=no-name-in-module,import-error +from openvino.frontend import FrontEnd, Place # pylint: disable=no-name-in-module,import-error from ngraph.utils.types import get_element_type # pylint: disable=no-name-in-module,import-error diff --git a/model-optimizer/mo/utils/check_ie_bindings.py b/model-optimizer/mo/utils/check_ie_bindings.py index 7eb09282b2221b..e12030e8098558 100644 --- a/model-optimizer/mo/utils/check_ie_bindings.py +++ b/model-optimizer/mo/utils/check_ie_bindings.py @@ -58,7 +58,7 @@ def import_core_modules(silent: bool, path_to_module: str): import openvino # pylint: disable=import-error,no-name-in-module import ngraph # pylint: disable=import-error,no-name-in-module - import ngraph.frontend # pylint: disable=import-error,no-name-in-module + import openvino.frontend # pylint: disable=import-error,no-name-in-module if silent: return True diff --git a/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py b/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py index c1efeafd9b4a2c..286511b8fab2cc 100644 --- a/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py +++ b/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py @@ -25,7 +25,7 @@ # pylint: disable=no-name-in-module,import-error from ngraph import PartialShape - from ngraph.frontend import FrontEndManager + from openvino.frontend import FrontEndManager from ngraph.utils.types import get_element_type except Exception: diff --git a/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py b/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py index 3ca2e6b9431a2b..af703a9b798051 100644 --- a/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py +++ b/model-optimizer/unit_tests/mo/moc_frontend/moc_extractor_test_actual.py @@ -18,7 +18,7 @@ clear_setup, set_equal_data, set_max_port_counts # pylint: disable=no-name-in-module,import-error - from ngraph.frontend import FrontEndManager + from openvino.frontend import FrontEndManager except Exception: print("No mock frontend API available, " diff --git a/runtime/bindings/python/setup.py b/runtime/bindings/python/setup.py index 6a4dd6268b335b..1baaec2ec7ee4b 100644 --- a/runtime/bindings/python/setup.py +++ b/runtime/bindings/python/setup.py @@ -39,7 +39,7 @@ "ngraph.impl.op", "ngraph.impl.op.util", "ngraph.impl.passes", - "ngraph.frontend", + "openvino.frontend", "openvino", "openvino.opset1", "openvino.opset2", diff --git a/runtime/bindings/python/src/compatibility/pyngraph/CMakeLists.txt b/runtime/bindings/python/src/compatibility/pyngraph/CMakeLists.txt index dc0644adb86a80..db4c4c3ec4e5e7 100644 --- a/runtime/bindings/python/src/compatibility/pyngraph/CMakeLists.txt +++ b/runtime/bindings/python/src/compatibility/pyngraph/CMakeLists.txt @@ -54,7 +54,7 @@ pybind11_add_module(_${PROJECT_NAME} MODULE ${SOURCES}) target_include_directories(_${PROJECT_NAME} PRIVATE "../") -target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::core openvino::frontend::manager) +target_link_libraries(_${PROJECT_NAME} PRIVATE openvino::core) if(TARGET onnx_ngraph_frontend) add_dependencies(_${PROJECT_NAME} onnx_ngraph_frontend) From b9f4dd47dfd7dbbde05385b4a9703b75c5412679 Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Thu, 21 Oct 2021 09:48:02 +0300 Subject: [PATCH 08/10] Fix code style cpp --- runtime/bindings/python/src/pyopenvino/pyopenvino.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp index e83ed365ba57c7..ae06e5ff54b586 100644 --- a/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp +++ b/runtime/bindings/python/src/pyopenvino/pyopenvino.cpp @@ -34,6 +34,10 @@ #include "pyopenvino/core/ie_version.hpp" #include "pyopenvino/core/tensor.hpp" #include "pyopenvino/core/tensor_description.hpp" +#include "pyopenvino/frontend/frontend.hpp" +#include "pyopenvino/frontend/frontend_manager.hpp" +#include "pyopenvino/frontend/inputmodel.hpp" +#include "pyopenvino/frontend/place.hpp" #include "pyopenvino/graph/dimension.hpp" #include "pyopenvino/graph/ops/constant.hpp" #include "pyopenvino/graph/ops/parameter.hpp" @@ -47,10 +51,6 @@ #include "pyopenvino/graph/types/regmodule_graph_types.hpp" #include "pyopenvino/graph/util.hpp" #include "pyopenvino/graph/variant.hpp" -#include "pyopenvino/frontend/frontend.hpp" -#include "pyopenvino/frontend/frontend_manager.hpp" -#include "pyopenvino/frontend/inputmodel.hpp" -#include "pyopenvino/frontend/place.hpp" namespace py = pybind11; From aa13c5d8dcd1e63071d27e8943131b3783421591 Mon Sep 17 00:00:00 2001 From: Bartek Szmelczynski Date: Thu, 21 Oct 2021 16:04:24 +0200 Subject: [PATCH 09/10] Bind exec core ov (#50) * bind core, exec_net classes * rm unused function * add new line --- .../bindings/python/src/openvino/__init__.py | 1 + .../bindings/python/src/openvino/ie_api.py | 6 + .../python/src/openvino/impl/__init__.py | 2 +- .../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(+), 471 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 6919158fa31594..2927b2b0919332 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 061318d29f90c6..151643720c4292 100644 --- a/runtime/bindings/python/src/openvino/ie_api.py +++ b/runtime/bindings/python/src/openvino/ie_api.py @@ -13,6 +13,7 @@ from openvino.pyopenvino import TBlobUint8 from openvino.pyopenvino import TensorDesc from openvino.pyopenvino import InferRequest +from openvino.pyopenvino import Tensor import numpy as np @@ -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 4a33b52aff7798..1b98dda28d1d3c 100644 --- a/runtime/bindings/python/src/openvino/impl/__init__.py +++ b/runtime/bindings/python/src/openvino/impl/__init__.py @@ -47,6 +47,6 @@ from openvino.pyopenvino import AxisSet from openvino.pyopenvino import AxisVector from openvino.pyopenvino import Coordinate -from openvino.pyopenvino import Output +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 816c3ebfa09081..1c23f4ca594592 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" @@ -89,7 +89,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); @@ -110,6 +109,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 4143e4c4c03a80..b89240f89f9fad 100644 --- a/runtime/bindings/python/tests/__init__.py +++ b/runtime/bindings/python/tests/__init__.py @@ -144,3 +144,4 @@ def xfail_test(reason="Mark the test as expected to fail", strict=True): xfail_issue_63137 = xfail_test(reason="Unsupported operations: OptionalHasElement, OptionalGetElement") 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_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 038eb5fdff2d1b..f33716c51a2cb3 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 @@ -45,9 +45,9 @@ def read_image(): 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") @@ -69,10 +69,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) @@ -90,38 +90,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() @@ -144,8 +144,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 From 192cd92b92645cf28fdbeb197e7c3f32e89c81cb Mon Sep 17 00:00:00 2001 From: Alexey Lebedev Date: Tue, 26 Oct 2021 13:11:46 +0300 Subject: [PATCH 10/10] refactor a few lines --- model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py | 2 +- runtime/bindings/python/src/openvino/frontend/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py b/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py index 286511b8fab2cc..73e18669350eeb 100644 --- a/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py +++ b/model-optimizer/unit_tests/mo/frontend_ngraph_test_actual.py @@ -26,7 +26,7 @@ # pylint: disable=no-name-in-module,import-error from ngraph import PartialShape from openvino.frontend import FrontEndManager - from ngraph.utils.types import get_element_type + from openvino.utils.types import get_element_type except Exception: print("No mock frontend API available, " diff --git a/runtime/bindings/python/src/openvino/frontend/__init__.py b/runtime/bindings/python/src/openvino/frontend/__init__.py index a73361b076722f..1aee19f6bc43f4 100644 --- a/runtime/bindings/python/src/openvino/frontend/__init__.py +++ b/runtime/bindings/python/src/openvino/frontend/__init__.py @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 """ -Package: ngraph +Package: openvino Low level wrappers for the FrontEnd c++ api. """