From 38bbc30a29680f7690fc086c4b08d642927aa4ce Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Wed, 15 Dec 2021 21:24:35 +0100 Subject: [PATCH 1/7] [ONNX] Fix memleak caused by shared_ptr cyclic dependency (#9236) ONNXFrameworkNode had it own copy of shared_ptr so in convert phase, it can be used to produce real ngraph nodes (by graph->make_ng_nodes(..)). But Graph also keeps ONNXFrameworkNodes in its cache and in consequence its own shared_ptr, which is causing a dependency cycle. This change removes shared_ptr from ONNXFrameworkNode class and moves it to decoded function runtime info, so Graph is in a single place now and its lifetime ends when decoded function is destroyed. --- .../tests/test_frontend/test_frontend_onnx.py | 50 ++++++++++++++++--- src/core/tests/onnx/onnx_import.in.cpp | 6 +-- .../onnx/frontend/src/core/graph.cpp | 16 +++--- .../onnx/frontend/src/core/graph.hpp | 2 + .../onnx/frontend/src/onnx_framework_node.cpp | 6 ++- .../onnx/frontend/src/onnx_framework_node.hpp | 42 +++++++--------- .../onnx/frontend/src/utils/onnx_internal.cpp | 9 +++- 7 files changed, 89 insertions(+), 42 deletions(-) diff --git a/src/bindings/python/tests/test_frontend/test_frontend_onnx.py b/src/bindings/python/tests/test_frontend/test_frontend_onnx.py index 7c36999c9cd..f691e55bdb6 100644 --- a/src/bindings/python/tests/test_frontend/test_frontend_onnx.py +++ b/src/bindings/python/tests/test_frontend/test_frontend_onnx.py @@ -26,6 +26,32 @@ def create_onnx_model(): return make_model(graph, producer_name="ngraph ONNX Importer") +def create_onnx_model_with_subgraphs(): + A = onnx.helper.make_tensor_value_info("A", onnx.TensorProto.FLOAT, [3]) + B = onnx.helper.make_tensor_value_info("B", onnx.TensorProto.FLOAT, [3]) + add_out = onnx.helper.make_tensor_value_info("add_out", onnx.TensorProto.FLOAT, [3]) + sub_out = onnx.helper.make_tensor_value_info("sub_out", onnx.TensorProto.FLOAT, [3]) + + add = onnx.helper.make_node("Add", inputs=["A", "B"], outputs=["add_out"]) + sub = onnx.helper.make_node("Sub", inputs=["A", "B"], outputs=["sub_out"]) + + then_body = make_graph([add], "then_body", [], [add_out]) + else_body = make_graph([sub], "else_body", [], [sub_out]) + + if_node = onnx.helper.make_node( + "If", + inputs=["cond"], + outputs=["res"], + then_branch=then_body, + else_branch=else_body + ) + cond = onnx.helper.make_tensor_value_info("cond", onnx.TensorProto.BOOL, []) + res = onnx.helper.make_tensor_value_info("res", onnx.TensorProto.FLOAT, [3]) + + graph = make_graph([if_node], "graph", [cond, A, B], [res]) + return make_model(graph, producer_name="ngraph ONNX Importer") + + def run_function(function, *inputs, expected): runtime = get_runtime() computation = runtime.computation(function) @@ -37,15 +63,18 @@ def run_function(function, *inputs, expected): fem = FrontEndManager() onnx_model_filename = "model.onnx" +onnx_model_with_subgraphs_filename = "model_subgraphs.onnx" ONNX_FRONTEND_NAME = "onnx" def setup_module(): onnx.save_model(create_onnx_model(), onnx_model_filename) + onnx.save_model(create_onnx_model_with_subgraphs(), onnx_model_with_subgraphs_filename) def teardown_module(): os.remove(onnx_model_filename) + os.remove(onnx_model_with_subgraphs_filename) def skip_if_onnx_frontend_is_disabled(): @@ -72,17 +101,29 @@ def test_convert(): run_function(function, a, b, expected=[expected]) -def test_decode_and_convert(): +@pytest.mark.parametrize("model_filename, inputs, expected", [ + [onnx_model_filename, + [np.array([[1, 2], [3, 4]], dtype=np.float32), + np.array([[2, 3], [4, 5]], dtype=np.float32)], + np.array([[1.5, 5], [10.5, 18]], dtype=np.float32)], + [onnx_model_with_subgraphs_filename, + [np.array(False, dtype=bool), + np.array([1, 2, 3], dtype=np.float32), + np.array([2, 3, 5], dtype=np.float32)], + np.array([-1, -1, -2], dtype=np.float32)], +]) +def test_decode_and_convert(model_filename, inputs, expected): skip_if_onnx_frontend_is_disabled() fe = fem.load_by_framework(framework=ONNX_FRONTEND_NAME) assert fe - model = fe.load(onnx_model_filename) + model = fe.load(model_filename) assert model decoded_function = fe.decode(model) assert decoded_function + for op in decoded_function.get_ordered_ops(): assert op.get_type_name() in ["Parameter", "Constant", "ONNXFrameworkNode", "ONNXSubgraphFrameworkNode", "Result"] @@ -92,10 +133,7 @@ def test_decode_and_convert(): for op in decoded_function.get_ordered_ops(): assert op.get_type_name() not in ["ONNXFrameworkNode", "ONNXSubgraphFrameworkNode"] - a = np.array([[1, 2], [3, 4]], dtype=np.float32) - b = np.array([[2, 3], [4, 5]], dtype=np.float32) - expected = np.array([[1.5, 5], [10.5, 18]], dtype=np.float32) - run_function(decoded_function, a, b, expected=[expected]) + run_function(decoded_function, *inputs, expected=[expected]) def test_load_by_model(): diff --git a/src/core/tests/onnx/onnx_import.in.cpp b/src/core/tests/onnx/onnx_import.in.cpp index efac638d743..100c8a2d720 100644 --- a/src/core/tests/onnx/onnx_import.in.cpp +++ b/src/core/tests/onnx/onnx_import.in.cpp @@ -380,7 +380,7 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_initializer_wo_input) { test_case.run(); } -NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function) { +NGRAPH_TEST(${BACKEND_NAME}, onnx_expand_function) { const auto function = onnx_import::import_onnx_model( file_util::path_join(SERIALIZED_ZOO, "onnx/quantization/dynamicquantizelinear.onnx")); @@ -392,7 +392,7 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function) { test_case.run(); } -NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function_dependency_to_created_subgraph) { +NGRAPH_TEST(${BACKEND_NAME}, onnx_expand_function_dependency_to_created_subgraph) { const auto function = onnx_import::import_onnx_model( file_util::path_join(SERIALIZED_ZOO, "onnx/transformations/greater_or_equal.onnx")); @@ -403,7 +403,7 @@ NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_function_dependency_to_created_sub test_case.run(); } -NGRAPH_TEST(onnx_${BACKEND_NAME}, onnx_expand_context_dependent_function) { +NGRAPH_TEST(${BACKEND_NAME}, onnx_expand_context_dependent_function) { auto function = onnx_import::import_onnx_model( file_util::path_join(SERIALIZED_ZOO, "onnx/transformations/softmax_crossentropy_consumed.onnx")); diff --git a/src/frontends/onnx/frontend/src/core/graph.cpp b/src/frontends/onnx/frontend/src/core/graph.cpp index 2c76c62d377..212766fc550 100644 --- a/src/frontends/onnx/frontend/src/core/graph.cpp +++ b/src/frontends/onnx/frontend/src/core/graph.cpp @@ -199,9 +199,10 @@ void Graph::decode_to_framework_nodes() { if (node.has_subgraphs()) { const auto& subgraphs = node.get_subgraphs(); auto inputs = node.get_ng_inputs(); + std::vector> functions; for (const auto& kv : subgraphs) { auto& subgraph = kv.second; - subgraph->decode(); + functions.push_back(subgraph->decode()); for (const auto& input : subgraph->get_inputs_from_parent()) { const auto& name = input.get_node()->get_friendly_name(); if (std::find_if(inputs.begin(), inputs.end(), [&name](const Output& n) -> bool { @@ -211,10 +212,9 @@ void Graph::decode_to_framework_nodes() { } } } - framework_node = - std::make_shared(shared_from_this(), node, inputs); + framework_node = std::make_shared(node, functions, inputs); } else { - framework_node = std::make_shared(shared_from_this(), node); + framework_node = std::make_shared(node); } OutputVector ng_nodes{framework_node->outputs()}; set_friendly_names(node, ng_nodes); @@ -240,7 +240,10 @@ std::shared_ptr Graph::create_function() { std::shared_ptr Graph::decode() { decode_to_framework_nodes(); - return create_function(); + auto function = create_function(); + auto& rt_info = function->get_rt_info(); + rt_info[ONNX_GRAPH_RT_ATTRIBUTE] = shared_from_this(); + return function; } bool Graph::is_ng_node_in_cache(const std::string& name) const { @@ -399,7 +402,8 @@ void Subgraph::find_inputs_from_parent() { for (const auto& out_name : node_proto.output()) { if (m_cache->contains(out_name)) { auto node_to_replace_input = m_cache->get_node(out_name).get_node(); - if (!dynamic_cast(node_to_replace_input)) + if (!ov::is_type(node_to_replace_input) && + !ov::is_type(node_to_replace_input)) continue; auto inputs = node_to_replace_input->input_values(); for (size_t i = 0; i < inputs.size(); i++) { diff --git a/src/frontends/onnx/frontend/src/core/graph.hpp b/src/frontends/onnx/frontend/src/core/graph.hpp index a7a983b038a..0e5c2378d32 100644 --- a/src/frontends/onnx/frontend/src/core/graph.hpp +++ b/src/frontends/onnx/frontend/src/core/graph.hpp @@ -121,6 +121,8 @@ inline std::ostream& operator<<(std::ostream& outs, const Graph& graph) { return (outs << ""); } +static const char* const ONNX_GRAPH_RT_ATTRIBUTE = "onnx_graph"; + } // namespace onnx_import } // namespace ngraph diff --git a/src/frontends/onnx/frontend/src/onnx_framework_node.cpp b/src/frontends/onnx/frontend/src/onnx_framework_node.cpp index bac360586d3..22eb9b56299 100644 --- a/src/frontends/onnx/frontend/src/onnx_framework_node.cpp +++ b/src/frontends/onnx/frontend/src/onnx_framework_node.cpp @@ -21,10 +21,14 @@ namespace frontend { NGRAPH_RTTI_DEFINITION(ONNXFrameworkNode, "ONNXFrameworkNode", 1); std::shared_ptr ONNXFrameworkNode::clone_with_new_inputs(const OutputVector& inputs) const { - return std::make_shared(m_graph, m_node, inputs); + return std::make_shared(m_node, inputs); } NGRAPH_RTTI_DEFINITION(ONNXSubgraphFrameworkNode, "ONNXSubgraphFrameworkNode", 1); +std::shared_ptr ONNXSubgraphFrameworkNode::clone_with_new_inputs(const OutputVector& inputs) const { + return std::make_shared(m_node, m_functions, inputs); +} + } // namespace frontend } // namespace ngraph diff --git a/src/frontends/onnx/frontend/src/onnx_framework_node.hpp b/src/frontends/onnx/frontend/src/onnx_framework_node.hpp index 852a3f07b09..8e52dd3dd18 100644 --- a/src/frontends/onnx/frontend/src/onnx_framework_node.hpp +++ b/src/frontends/onnx/frontend/src/onnx_framework_node.hpp @@ -38,20 +38,16 @@ class ONNXFrameworkNode : public ov::op::util::FrameworkNode { public: NGRAPH_RTTI_DECLARATION; - ONNXFrameworkNode(std::shared_ptr graph, const onnx_import::Node& node) + ONNXFrameworkNode(const onnx_import::Node& node) : ov::op::util::FrameworkNode(node.get_ng_inputs(), node.get_outputs_size()), - m_node(node), - m_graph(graph) {} + m_node(node) {} - ONNXFrameworkNode(std::shared_ptr graph, - const onnx_import::Node& node, - const OutputVector& inputs) + ONNXFrameworkNode(const onnx_import::Node& node, const OutputVector& inputs) : ov::op::util::FrameworkNode(inputs, node.get_outputs_size()), - m_node(node), - m_graph(graph) {} + m_node(node) {} - OutputVector get_ng_nodes() const { - OutputVector ng_nodes{m_graph->make_ng_nodes(m_node)}; + OutputVector get_ng_nodes(const std::shared_ptr& graph) const { + OutputVector ng_nodes{graph->make_ng_nodes(m_node)}; if (ng_nodes.size() > get_output_size()) { ng_nodes.resize(get_output_size()); } @@ -71,35 +67,31 @@ public: protected: onnx_import::Node m_node; - -private: - std::shared_ptr m_graph; }; class ONNXSubgraphFrameworkNode : public ONNXFrameworkNode { public: NGRAPH_RTTI_DECLARATION; - ONNXSubgraphFrameworkNode(std::shared_ptr graph, - const onnx_import::Node& node, + ONNXSubgraphFrameworkNode(const onnx_import::Node& node, + const std::vector>& functions, const OutputVector& inputs) - : ONNXFrameworkNode(graph, node, inputs) {} + : ONNXFrameworkNode(node, inputs), + m_functions(functions) {} void infer_inputs_from_parent() { for (auto& subgraph : m_node.get_subgraphs()) subgraph.second->infer_inputs_from_parent(); } - std::vector> get_subgraph_functions() const { - std::vector> ret; - for (const auto& kv : m_node.get_subgraphs()) { - auto& subgraph = kv.second; - ret.push_back(std::make_shared(subgraph->get_ng_outputs(), - subgraph->get_ng_parameters(), - subgraph->get_name())); - } - return ret; + const std::vector>& get_subgraph_functions() const { + return m_functions; } + + virtual std::shared_ptr clone_with_new_inputs(const OutputVector& inputs) const override; + +private: + std::vector> m_functions; }; } // namespace frontend diff --git a/src/frontends/onnx/frontend/src/utils/onnx_internal.cpp b/src/frontends/onnx/frontend/src/utils/onnx_internal.cpp index 930c8fab619..aff727c9fa8 100644 --- a/src/frontends/onnx/frontend/src/utils/onnx_internal.cpp +++ b/src/frontends/onnx/frontend/src/utils/onnx_internal.cpp @@ -60,6 +60,12 @@ void apply_transformations(ONNX_NAMESPACE::ModelProto& model_proto, const std::s } // namespace void convert_decoded_function(std::shared_ptr function) { + auto& rt_info = function->get_rt_info(); + auto it = rt_info.find(ONNX_GRAPH_RT_ATTRIBUTE); + OPENVINO_ASSERT(it != rt_info.end(), + "Could not find '" + std::string(ONNX_GRAPH_RT_ATTRIBUTE) + + "' attribute in decoded model. Model probably wasn't created by FrontEnd::decode function."); + auto onnx_graph = it->second.as>(); for (const auto& node : function->get_ordered_ops()) { if (auto raw_node = std::dynamic_pointer_cast(node)) { if (auto subgraph_node = std::dynamic_pointer_cast(node)) { @@ -68,7 +74,7 @@ void convert_decoded_function(std::shared_ptr function) { convert_decoded_function(function); } } - auto ng_nodes = raw_node->get_ng_nodes(); + auto ng_nodes = raw_node->get_ng_nodes(onnx_graph); replace_node(raw_node, ng_nodes); } else { // Have to revalidate node because new intpus can affect shape/type @@ -76,6 +82,7 @@ void convert_decoded_function(std::shared_ptr function) { node->revalidate_and_infer_types(); } } + rt_info.erase(it); detail::remove_dangling_parameters(function); detail::remove_dangling_results(function); } From b64329430071ab8af0cb7de75e025859b517b463 Mon Sep 17 00:00:00 2001 From: Andrey Noskov Date: Wed, 15 Dec 2021 23:39:31 +0300 Subject: [PATCH 2/7] [GNA] Added import/export test (#8769) * [GNA] Added import/export test - still need fixes * Fixed inputs and const vals * Parametrized input shape for import base test * Deleted commented code * Fixed input shape in test * Fixed SF for import --- .../import_export_batch_size.cpp | 91 +++++++++++++++++++ .../import_export_multi_inputs.cpp | 11 ++- .../import_reshape_permute_conv.cpp | 6 ++ .../import_export_tests/import_nonzero.cpp | 3 + .../import_export_base/import_export_base.hpp | 1 + .../import_export_base/import_export_base.cpp | 4 +- .../import_export_tests/import_nonzero.cpp | 5 +- .../import_reshape_permute_conv.cpp | 5 +- 8 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 src/tests/functional/plugin/gna/Import_export_tests/import_export_batch_size.cpp diff --git a/src/tests/functional/plugin/gna/Import_export_tests/import_export_batch_size.cpp b/src/tests/functional/plugin/gna/Import_export_tests/import_export_batch_size.cpp new file mode 100644 index 00000000000..da0e3c88a12 --- /dev/null +++ b/src/tests/functional/plugin/gna/Import_export_tests/import_export_batch_size.cpp @@ -0,0 +1,91 @@ +// Copyright (C) 2018-2021 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ngraph_functions/builders.hpp" +#include "base/import_export_base/import_export_base.hpp" + +namespace LayerTestDefinitions { + +class ImportBatchTest : public FuncTestUtils::ImportNetworkTestBase { +protected: + InferenceEngine::Blob::Ptr GenerateInput(const InferenceEngine::InputInfo& info) const override { + return FuncTestUtils::createAndFillBlob(info.getTensorDesc(), 0.2f, -0.1f); + } + + void SetUp() override { + InferenceEngine::Precision netPrecision; + std::vector inputShape; + std::string _; + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, _) = this->GetParam(); + auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); + + auto params = ngraph::builder::makeParams(ngPrc, {inputShape}); + + auto mul_const_1 = ngraph::builder::makeConstant(ngPrc, { inputShape[1], 2048 }, + CommonTestUtils::generate_float_numbers(2048 * inputShape[1], -0.1f, 0.1f), false); + + auto matmul_1 = std::make_shared(params[0], mul_const_1); + auto sigmoid_1 = std::make_shared(matmul_1); + + auto mul_const_2 = ngraph::builder::makeConstant(ngPrc, { 2048, 3425 }, + CommonTestUtils::generate_float_numbers(2048 * 3425, -0.1f, 0.1f), false); + + auto matmul_2 = std::make_shared(sigmoid_1, mul_const_2); + + function = std::make_shared(matmul_2, params, "ExportImportNetwork"); + } +}; + +TEST_P(ImportBatchTest, CompareWithRefImpl) { + Run(); +}; + +const std::vector> inputShapes = { + {1, 440}, + {2, 440}, + {4, 128} +}; + +const std::vector netPrecisions = { + InferenceEngine::Precision::FP32, + InferenceEngine::Precision::FP16 +}; + +const std::vector> exportConfigs = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"}, + {"GNA_SCALE_FACTOR_0", "327.67"} + } +}; + +const std::vector> importConfigs = { + { + {"GNA_DEVICE_MODE", "GNA_SW_EXACT"} + } +}; + +const std::vector appHeader = { + "" +}; + +INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkBatchCase, ImportBatchTest, + ::testing::Combine( + ::testing::ValuesIn(inputShapes), + ::testing::ValuesIn(netPrecisions), + ::testing::Values(CommonTestUtils::DEVICE_GNA), + ::testing::ValuesIn(exportConfigs), + ::testing::ValuesIn(importConfigs), + ::testing::ValuesIn(appHeader)), + ImportBatchTest::getTestCaseName); +} // namespace LayerTestDefinitions diff --git a/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp b/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp index c2e381b5542..487dcf3f4e1 100644 --- a/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp +++ b/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_export_multi_inputs.cpp @@ -17,11 +17,12 @@ namespace LayerTestsDefinitions { class ImportMultiInput : public FuncTestUtils::ImportNetworkTestBase { protected: void SetUp() override { + std::vector inputShape; InferenceEngine::Precision netPrecision; - std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto input = ngraph::builder::makeParams(ngPrc, {{1, 10}, {1, 10}}); + auto input = ngraph::builder::makeParams(ngPrc, {inputShape, inputShape}); auto mul1 = ngraph::builder::makeEltwise(input[0], input[1], ngraph::helpers::EltwiseTypes::ADD); auto result = std::make_shared(mul1); @@ -40,6 +41,10 @@ TEST_P(ImportMultiInputChanged, CompareWithRefImpl) { TestRun(true); }; +const std::vector> inputShape = { + {1, 10} +}; + const std::vector netPrecisions = { InferenceEngine::Precision::FP32 }; @@ -98,6 +103,7 @@ const std::vector> importConfigsUnchanged = { INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputUnchanged, ::testing::Combine( + ::testing::ValuesIn(inputShape), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), @@ -107,6 +113,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputUnchanged, INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportMultiInputChanged, ::testing::Combine( + ::testing::ValuesIn(inputShape), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), diff --git a/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp b/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp index 110b0fd66fe..0f8bd3d1fc9 100644 --- a/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp +++ b/src/tests/functional/plugin/gna/shared_tests_instances/import_export_tests/import_reshape_permute_conv.cpp @@ -52,6 +52,10 @@ TEST_P(ImportExportGNAModelChanged, ReshapePermuteConv) { TestRun(true); }; +const std::vector> inputShapes = { + {1, 336} +}; + const std::vector netPrecisions = { InferenceEngine::Precision::FP32, InferenceEngine::Precision::FP16 @@ -92,6 +96,7 @@ const std::vector appHeaders = { INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportExportGNAModelUnchanged, ::testing::Combine( + ::testing::ValuesIn(inputShapes), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), @@ -101,6 +106,7 @@ INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportExportGNAModelUnchanged, INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkGNA, ImportExportGNAModelChanged, ::testing::Combine( + ::testing::ValuesIn(inputShapes), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_GNA), ::testing::ValuesIn(exportConfigs), diff --git a/src/tests/functional/plugin/myriad/shared_tests_instances/import_export_tests/import_nonzero.cpp b/src/tests/functional/plugin/myriad/shared_tests_instances/import_export_tests/import_nonzero.cpp index 4555ac1ec9d..888ac6eb712 100644 --- a/src/tests/functional/plugin/myriad/shared_tests_instances/import_export_tests/import_nonzero.cpp +++ b/src/tests/functional/plugin/myriad/shared_tests_instances/import_export_tests/import_nonzero.cpp @@ -26,8 +26,11 @@ const std::vector appHeaders = { "APPLICATION_HEADER" }; +std::vector inputShape = ngraph::Shape{1000}; + INSTANTIATE_TEST_SUITE_P(smoke_ImportNetworkCase, ImportNonZero, ::testing::Combine( + ::testing::Values(inputShape), ::testing::ValuesIn(netPrecisions), ::testing::Values(CommonTestUtils::DEVICE_MYRIAD), ::testing::ValuesIn(exportConfigs), diff --git a/src/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp b/src/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp index 8795dced06f..e6ce7a46165 100644 --- a/src/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp +++ b/src/tests/functional/plugin/shared/include/base/import_export_base/import_export_base.hpp @@ -9,6 +9,7 @@ #include typedef std::tuple< + std::vector, // Input Shape InferenceEngine::Precision, // Network Precision std::string, // Target Device std::map, // Export Configuration diff --git a/src/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp b/src/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp index 3f7e6e0f149..be782eb6687 100644 --- a/src/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp +++ b/src/tests/functional/plugin/shared/src/base/import_export_base/import_export_base.cpp @@ -9,14 +9,16 @@ namespace FuncTestUtils { std::string ImportNetworkTestBase::getTestCaseName(testing::TestParamInfo obj) { + std::vector inputShape; InferenceEngine::Precision netPrecision; std::string targetDevice; std::map exportConfiguration; std::map importConfiguration; std::string appHeader; - std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param; + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, appHeader) = obj.param; std::ostringstream result; + result << "IS=" << CommonTestUtils::vec2str(inputShape) << "_"; result << "netPRC=" << netPrecision.name() << "_"; result << "targetDevice=" << targetDevice << "_"; for (auto const& configItem : exportConfiguration) { diff --git a/src/tests/functional/plugin/shared/src/import_export_tests/import_nonzero.cpp b/src/tests/functional/plugin/shared/src/import_export_tests/import_nonzero.cpp index 44ed3eff75c..64d3ad1192f 100644 --- a/src/tests/functional/plugin/shared/src/import_export_tests/import_nonzero.cpp +++ b/src/tests/functional/plugin/shared/src/import_export_tests/import_nonzero.cpp @@ -10,10 +10,11 @@ namespace LayerTestsDefinitions { void ImportNonZero::SetUp() { InferenceEngine::Precision netPrecision; - std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); + ngraph::Shape inputShape; + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); const auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - const auto parameter = std::make_shared(ngPrc, ngraph::Shape{1000}); + const auto parameter = std::make_shared(ngPrc, inputShape); const auto nonZero = std::make_shared(parameter); function = std::make_shared(nonZero->outputs(), ngraph::ParameterVector{parameter}, "ExportImportNetwork"); diff --git a/src/tests/functional/plugin/shared/src/import_export_tests/import_reshape_permute_conv.cpp b/src/tests/functional/plugin/shared/src/import_export_tests/import_reshape_permute_conv.cpp index 5a6cb6b6ba6..664aa444854 100644 --- a/src/tests/functional/plugin/shared/src/import_export_tests/import_reshape_permute_conv.cpp +++ b/src/tests/functional/plugin/shared/src/import_export_tests/import_reshape_permute_conv.cpp @@ -9,11 +9,12 @@ namespace LayerTestsDefinitions { void ImportReshapePermuteConv::SetUp() { + std::vector inputShape; InferenceEngine::Precision netPrecision; - std::tie(netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); + std::tie(inputShape, netPrecision, targetDevice, exportConfiguration, importConfiguration, applicationHeader) = this->GetParam(); auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); - auto params = ngraph::builder::makeParams(ngPrc, { {1, 336} }); + auto params = ngraph::builder::makeParams(ngPrc, { inputShape }); std::vector outFormShapes1 = { 1, 1, 168, 2 }; auto pattern1 = std::make_shared(ngraph::element::Type_t::i64, ngraph::Shape{ 4 }, outFormShapes1); From 0b9158c2b82f5ec44eeaef76599614a2b29f8991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ko=C5=BCykowski?= Date: Wed, 15 Dec 2021 21:40:43 +0100 Subject: [PATCH 3/7] Extend ONNX FE for operation Softmax-8 (#9189) --- .../onnx/softmax_axis_1_opset11.prototxt | 56 ++++++ .../softmax_axis_negative_1_opset11.prototxt | 56 ++++++ .../softmax_axis_negative_1_opset13.prototxt | 56 ++++++ src/core/tests/onnx/onnx_import.in.cpp | 162 ++++++++++++++---- .../onnx/frontend/src/op/softmax.cpp | 25 +-- 5 files changed, 296 insertions(+), 59 deletions(-) create mode 100644 src/core/tests/models/onnx/softmax_axis_1_opset11.prototxt create mode 100644 src/core/tests/models/onnx/softmax_axis_negative_1_opset11.prototxt create mode 100644 src/core/tests/models/onnx/softmax_axis_negative_1_opset13.prototxt diff --git a/src/core/tests/models/onnx/softmax_axis_1_opset11.prototxt b/src/core/tests/models/onnx/softmax_axis_1_opset11.prototxt new file mode 100644 index 00000000000..947b381db0b --- /dev/null +++ b/src/core/tests/models/onnx/softmax_axis_1_opset11.prototxt @@ -0,0 +1,56 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "x" + output: "y" + op_type: "Softmax" + attribute { + name: "axis" + i: 1 + type: INT + } + } + name: "test_softmax_axis_1" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + dim { + dim_value: 5 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + dim { + dim_value: 5 + } + } + } + } + } +} +opset_import { + version: 11 +} diff --git a/src/core/tests/models/onnx/softmax_axis_negative_1_opset11.prototxt b/src/core/tests/models/onnx/softmax_axis_negative_1_opset11.prototxt new file mode 100644 index 00000000000..ad9a4b72603 --- /dev/null +++ b/src/core/tests/models/onnx/softmax_axis_negative_1_opset11.prototxt @@ -0,0 +1,56 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "x" + output: "y" + op_type: "Softmax" + attribute { + name: "axis" + i: -1 + type: INT + } + } + name: "test_softmax_axis_0" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + dim { + dim_value: 5 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + dim { + dim_value: 5 + } + } + } + } + } +} +opset_import { + version: 11 +} diff --git a/src/core/tests/models/onnx/softmax_axis_negative_1_opset13.prototxt b/src/core/tests/models/onnx/softmax_axis_negative_1_opset13.prototxt new file mode 100644 index 00000000000..aff3afc2c52 --- /dev/null +++ b/src/core/tests/models/onnx/softmax_axis_negative_1_opset13.prototxt @@ -0,0 +1,56 @@ +ir_version: 3 +producer_name: "nGraph ONNX Importer" +graph { + node { + input: "x" + output: "y" + op_type: "Softmax" + attribute { + name: "axis" + i: -1 + type: INT + } + } + name: "test_softmax_axis_0" + input { + name: "x" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + dim { + dim_value: 5 + } + } + } + } + } + output { + name: "y" + type { + tensor_type { + elem_type: 1 + shape { + dim { + dim_value: 3 + } + dim { + dim_value: 4 + } + dim { + dim_value: 5 + } + } + } + } + } +} +opset_import { + version: 13 +} diff --git a/src/core/tests/onnx/onnx_import.in.cpp b/src/core/tests/onnx/onnx_import.in.cpp index 100c8a2d720..73f02233e0f 100644 --- a/src/core/tests/onnx/onnx_import.in.cpp +++ b/src/core/tests/onnx/onnx_import.in.cpp @@ -690,19 +690,24 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_1D) { } namespace { // common input for all Softmax 3D test cases (Shape = {3,4,5}) +// clang-format off const std::vector SOFTMAX_INPUT = { - 2.75793882, -0.50841322, 0.82013929, -0.62409912, -0.96136118, 0.21004745, 1.38337255, - 1.19030397, 2.0940445, -0.03551657, -0.78686039, 1.992782, 0.04300319, -0.29230777, - -0.56797112, -1.26732165, -0.61935399, 0.57670432, 0.92844898, 2.82469233, + 2.75793882, -0.50841322, 0.82013929, -0.62409912, -0.96136118, + 0.21004745, 1.38337255, 1.19030397, 2.0940445, -0.03551657, + -0.78686039, 1.992782, 0.04300319, -0.29230777, -0.56797112, + -1.26732165, -0.61935399, 0.57670432, 0.92844898, 2.82469233, - 0.98721677, -0.05100663, -1.21178917, -0.17530157, 1.40051805, -0.13259761, -1.14313018, - 0.2673723, -0.87996154, 1.29053106, 1.55, 0.8396538, 1.20729817, 0.23727845, - -0.89113606, -1.70909842, 0.26460363, -0.70566808, 2.383518, 1.07024615, + 0.98721677, -0.05100663, -1.21178917, -0.17530157, 1.40051805, + -0.13259761, -1.14313018, 0.2673723, -0.87996154, 1.29053106, + 1.55, 0.8396538, 1.20729817, 0.23727845, -0.89113606, + -1.70909842, 0.26460363, -0.70566808, 2.383518, 1.07024615, - -1.21722605, 0.82919357, 0.55765697, 0.12657686, 0.63432172, 0.75425957, -2.43721014, - -1.24478184, 2.65316853, 1.19509542, -0.95523998, 0.5149006, -0.01151649, 0.68327026, - -0.4589638, -0.46554745, 0.21055324, 0.39266729, 2.05098086, 1.83207919}; + -1.21722605, 0.82919357, 0.55765697, 0.12657686, 0.63432172, + 0.75425957, -2.43721014, -1.24478184, 2.65316853, 1.19509542, + -0.95523998, 0.5149006, -0.01151649, 0.68327026, -0.4589638, + -0.46554745, 0.21055324, 0.39266729, 2.05098086, 1.83207919}; } // namespace +// clang-format on NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_0) { auto function = onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_0.onnx")); @@ -710,19 +715,24 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_0) { auto test_case = test::TestCase(function, s_device); test_case.add_input(SOFTMAX_INPUT); + // clang-format off test_case.add_expected_output( Shape{3, 4, 5}, - {0.09683057, 0.00369363, 0.01394559, 0.00329012, 0.00234823, 0.00757665, 0.02449322, - 0.02019284, 0.04985249, 0.00592694, 0.00279593, 0.04505148, 0.00641108, 0.00458466, - 0.00348007, 0.00172928, 0.00330577, 0.01093237, 0.01554086, 0.10351497, + {0.09683057, 0.00369363, 0.01394559, 0.00329012, 0.00234823, + 0.00757665, 0.02449322, 0.02019284, 0.04985249, 0.00592694, + 0.00279593, 0.04505148, 0.00641108, 0.00458466, 0.00348007, + 0.00172928, 0.00330577, 0.01093237, 0.01554086, 0.10351497, - 0.01648154, 0.00583583, 0.00182802, 0.00515374, 0.02491679, 0.00537859, 0.00195794, - 0.00802367, 0.00254737, 0.0223216, 0.02893419, 0.0142204, 0.02053893, 0.00778581, - 0.00251907, 0.00111174, 0.00800149, 0.0030324, 0.06658917, 0.0179084, + 0.01648154, 0.00583583, 0.00182802, 0.00515374, 0.02491679, + 0.00537859, 0.00195794, 0.00802367, 0.00254737, 0.0223216, + 0.02893419, 0.0142204, 0.02053893, 0.00778581, 0.00251907, + 0.00111174, 0.00800149, 0.0030324, 0.06658917, 0.0179084, - 0.00181811, 0.01407243, 0.01072611, 0.0069699, 0.01158077, 0.01305647, 0.00053677, - 0.0017687, 0.08719896, 0.02028982, 0.00236265, 0.01027717, 0.0060709, 0.01216173, - 0.00388087, 0.00385541, 0.00758048, 0.00909469, 0.04775123, 0.03836337}); + 0.00181811, 0.01407243, 0.01072611, 0.0069699, 0.01158077, + 0.01305647, 0.00053677, 0.0017687, 0.08719896, 0.02028982, + 0.00236265, 0.01027717, 0.0060709, 0.01216173, 0.00388087, + 0.00385541, 0.00758048, 0.00909469, 0.04775123, 0.03836337}); + // clang-format on test_case.run(6); } @@ -733,35 +743,113 @@ NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_1) { auto test_case = test::TestCase(function, s_device); test_case.add_input(SOFTMAX_INPUT); + // clang-format off test_case.add_expected_output( Shape{3, 4, 5}, - {0.22757064, 0.00868076, 0.03277484, 0.00773243, 0.0055188, 0.0178066, 0.05756383, - 0.04745709, 0.11716303, 0.01392945, 0.00657097, 0.10587974, 0.01506727, 0.01077484, - 0.00817884, 0.00406413, 0.00776921, 0.0256932, 0.03652405, 0.24328028, + {0.22757064, 0.00868076, 0.03277484, 0.00773243, 0.0055188, + 0.0178066, 0.05756383, 0.04745709, 0.11716303, 0.01392945, + 0.00657097, 0.10587974, 0.01506727, 0.01077484, 0.00817884, + 0.00406413, 0.00776921, 0.0256932, 0.03652405, 0.24328028, - 0.06217413, 0.02201481, 0.00689594, 0.01944171, 0.09399488, 0.02028993, 0.00738604, - 0.03026811, 0.00960958, 0.08420492, 0.10914991, 0.05364435, 0.07748005, 0.02937079, - 0.0095028, 0.00419387, 0.03018442, 0.01143929, 0.2511977, 0.06755678, + 0.06217413, 0.02201481, 0.00689594, 0.01944171, 0.09399488, + 0.02028993, 0.00738604, 0.03026811, 0.00960958, 0.08420492, + 0.10914991, 0.05364435, 0.07748005, 0.02937079, 0.0095028, + 0.00419387, 0.03018442, 0.01143929, 0.2511977, 0.06755678, - 0.00587593, 0.04548053, 0.0346656, 0.02252594, 0.03742775, 0.04219705, 0.00173478, - 0.00571623, 0.2818174, 0.06557446, 0.00763582, 0.03321466, 0.01962049, 0.03930537, - 0.01254255, 0.01246025, 0.02449929, 0.02939305, 0.15432668, 0.12398617}); + 0.00587593, 0.04548053, 0.0346656, 0.02252594, 0.03742775, + 0.04219705, 0.00173478, 0.00571623, 0.2818174, 0.06557446, + 0.00763582, 0.03321466, 0.01962049, 0.03930537, 0.01254255, + 0.01246025, 0.02449929, 0.02939305, 0.15432668, 0.12398617}); + // clang-format on test_case.run(4); } -NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_1D) { - ASSERT_THROW( - onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_1D.onnx")), - ngraph::ngraph_error) - << "Softmax model with invalid axis was successfully imported while it should have thrown."; +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_1_opset11) { + auto function = + onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_1_opset11.onnx")); + + auto test_case = test::TestCase(function, s_device); + test_case.add_input(SOFTMAX_INPUT); + + // clang-format off + test_case.add_expected_output( + Shape{3, 4, 5}, + {0.88890495, 0.04825497, 0.27088348, 0.04490523, 0.02037154, + 0.06955369, 0.31998834, 0.39223197, 0.68041159, 0.05141776, + 0.02566661, 0.5885689, 0.12453075, 0.06257374, 0.03019055, + 0.01587475, 0.0431878, 0.21235381, 0.21210944, 0.89802015, + + 0.31752626, 0.19442629, 0.0546935, 0.06279221, 0.36823282, + 0.10362164, 0.06523066, 0.24006419, 0.03103672, 0.32987983, + 0.55743381, 0.473766, 0.61451431, 0.09486084, 0.03722801, + 0.02141829, 0.26657706, 0.090728, 0.81131024, 0.26465935, + + 0.08619648, 0.43343993, 0.3877785, 0.04523505, 0.15625437, + 0.61900597, 0.01653285, 0.06394322, 0.56592636, 0.27376196, + 0.11201305, 0.31654337, 0.21947994, 0.07893034, 0.05236297, + 0.18278451, 0.23348385, 0.32879834, 0.30990825, 0.5176207}); + // clang-format on + + test_case.run(4); } -NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_invalid_axis_3D) { - ASSERT_THROW( - onnx_import::import_onnx_model(file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_invalid_axis_3D.onnx")), - ngraph::ngraph_error) - << "Softmax model with invalid axis was successfully imported while it should have thrown."; +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_negative_1_opset11) { + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_negative_1_opset11.onnx")); + + auto test_case = test::TestCase(function); + test_case.add_input(SOFTMAX_INPUT); + + // clang-format off + test_case.add_expected_output( + Shape{3, 4, 5}, + {0.88890495, 0.04825497, 0.27088348, 0.04490523, 0.02037154, + 0.06955369, 0.31998834, 0.39223197, 0.68041159, 0.05141776, + 0.02566661, 0.5885689, 0.12453075, 0.06257374, 0.03019055, + 0.01587475, 0.0431878, 0.21235381, 0.21210944, 0.89802015, + + 0.31752626, 0.19442629, 0.0546935, 0.06279221, 0.36823282, + 0.10362164, 0.06523066, 0.24006419, 0.03103672, 0.32987983, + 0.55743381, 0.473766, 0.61451431, 0.09486084, 0.03722801, + 0.02141829, 0.26657706, 0.090728, 0.81131024, 0.26465935, + + 0.08619648, 0.43343993, 0.3877785, 0.04523505, 0.15625437, + 0.61900597, 0.01653285, 0.06394322, 0.56592636, 0.27376196, + 0.11201305, 0.31654337, 0.21947994, 0.07893034, 0.05236297, + 0.18278451, 0.23348385, 0.32879834, 0.30990825, 0.5176207}); + // clang-format on + + test_case.run(6); +} + +NGRAPH_TEST(${BACKEND_NAME}, onnx_model_softmax_axis_negative_1_opset13) { + auto function = onnx_import::import_onnx_model( + file_util::path_join(SERIALIZED_ZOO, "onnx/softmax_axis_negative_1_opset13.onnx")); + + auto test_case = test::TestCase(function); + test_case.add_input(SOFTMAX_INPUT); + + // clang-format off + test_case.add_expected_output( + Shape{3, 4, 5}, + {0.88890495, 0.04825497, 0.27088348, 0.04490523, 0.02037154, + 0.06955369, 0.31998834, 0.39223197, 0.68041159, 0.05141776, + 0.02566661, 0.5885689, 0.12453075, 0.06257374, 0.03019055, + 0.01587475, 0.0431878, 0.21235381, 0.21210944, 0.89802015, + + 0.31752626, 0.19442629, 0.0546935, 0.06279221, 0.36823282, + 0.10362164, 0.06523066, 0.24006419, 0.03103672, 0.32987983, + 0.55743381, 0.473766, 0.61451431, 0.09486084, 0.03722801, + 0.02141829, 0.26657706, 0.090728, 0.81131024, 0.26465935, + + 0.08619648, 0.43343993, 0.3877785, 0.04523505, 0.15625437, + 0.61900597, 0.01653285, 0.06394322, 0.56592636, 0.27376196, + 0.11201305, 0.31654337, 0.21947994, 0.07893034, 0.05236297, + 0.18278451, 0.23348385, 0.32879834, 0.30990825, 0.5176207}); + // clang-format on + + test_case.run(6); } NGRAPH_TEST(${BACKEND_NAME}, onnx_model_sub) { diff --git a/src/frontends/onnx/frontend/src/op/softmax.cpp b/src/frontends/onnx/frontend/src/op/softmax.cpp index 3aa517f3c12..ce609a52e44 100644 --- a/src/frontends/onnx/frontend/src/op/softmax.cpp +++ b/src/frontends/onnx/frontend/src/op/softmax.cpp @@ -37,17 +37,8 @@ OutputVector softmax(const Node& node) { result = default_opset::Constant::create(data.get_element_type(), Shape{}, {1}); break; } - case 1: { - // checks if the axis belongs to the allowed values set (-1 and 0 for 1D) - ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank()); - result = std::make_shared(data, 0); - break; - } default: { - const auto normalized_axis = - ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank()); - - result = onnx_softmax(data, normalized_axis); + result = onnx_softmax(data, axis); break; } } @@ -69,17 +60,8 @@ OutputVector softmax(const Node& node) { result = default_opset::Constant::create(data.get_element_type(), Shape{}, {1}); break; } - case 1: { - // checks if the axis belongs to the allowed values set (-1 and 0 for 1D) - ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank()); - result = std::make_shared(data, 0); - break; - } default: { - const auto normalized_axis = - ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank()); - - result = std::make_shared(data, normalized_axis); + result = std::make_shared(data, axis); break; } } @@ -92,9 +74,8 @@ OutputVector softmax(const Node& node) { const auto data = node.get_ng_inputs().at(0); const auto axis = node.get_attribute_value("axis", -1); - const auto normalized_axis = ngraph::normalize_axis(node.get_description(), axis, data.get_partial_shape().rank()); - return {std::make_shared(data, normalized_axis)}; + return {std::make_shared(data, axis)}; } } // namespace set_13 } // namespace op From d1e54d996112cb0eb425b65dc08904aa1ded7855 Mon Sep 17 00:00:00 2001 From: Irina Efode Date: Wed, 15 Dec 2021 23:43:24 +0300 Subject: [PATCH 4/7] [IE TESTS] Fix filters in report (#9232) --- .../layer_tests_summary/template/filters.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/filters.js b/src/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/filters.js index 6005190e7cc..beb86e1b65f 100644 --- a/src/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/filters.js +++ b/src/tests/ie_test_utils/functional_test_utils/layer_tests_summary/template/filters.js @@ -99,15 +99,15 @@ function filterTable() { if (implementation != 0) { if (implementation == 'ni') { $("#report #data tr:not(:hidden)").filter(function () { - $(this).toggle($(this).find('td').hasClass("not_impl")) + $(this).toggle($(this).find('td').hasClass("value " + device + " not_impl")) }); } else if (implementation == 'i') { $("#report #data tr:not(:hidden)").filter(function () { - $(this).toggle($(this).find('td').hasClass("impl")); + $(this).toggle($(this).find('td').hasClass("value " + device + " impl")); }); } else { $("#report #data tr:not(:hidden)").filter(function () { - $(this).toggle(!$(this).find('td').hasClass("not_impl") && !$(this).find('td').hasClass("impl")); + $(this).toggle(!$(this).find('td').hasClass("value")); }); } } @@ -116,19 +116,19 @@ function filterTable() { selector = []; select.forEach(item => { if (item == '100p') { - selector.push('.value:visible[crashed="0"][failed="0"][skipped="0"]'); + selector.push('.value:visible[crashed="0"][failed="0"][skipped="0"][value!="---"]'); } if (item == '100f') { - selector.push('.value:visible[passed="0"]'); + selector.push('.value:visible[passed="0"][value!="---"]'); } if (item == 'p') { - selector.push('.value:visible[passed!="0"]'); + selector.push('.value:visible[passed!="0"][value!="---"]'); } if (item == 'f') { - selector.push('.value:visible[failed!="0"]'); + selector.push('.value:visible[failed!="0"][value!="---"]'); } if (item == 'c') { - selector.push('.value:visible[crashed!="0"]'); + selector.push('.value:visible[crashed!="0"][value!="---"]'); } if (item == 's') { selector.push('.value:visible[value!="---"][skipped!="0"]'); From 40f668140ec6536b4d47e05f5185eb8ac5accf7e Mon Sep 17 00:00:00 2001 From: Mateusz Tabaka Date: Wed, 15 Dec 2021 23:52:26 +0100 Subject: [PATCH 5/7] Fix compilation error in template_plugin tests (#9248) --- .../tests/functional/op_reference/einsum.cpp | 8 ++++---- .../functional/op_reference/extract_image_patches.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/template_plugin/tests/functional/op_reference/einsum.cpp b/docs/template_plugin/tests/functional/op_reference/einsum.cpp index 31460fd2ccf..625521dc42b 100644 --- a/docs/template_plugin/tests/functional/op_reference/einsum.cpp +++ b/docs/template_plugin/tests/functional/op_reference/einsum.cpp @@ -30,7 +30,7 @@ class ReferenceEinsumTest : public testing::TestWithParam, public public: void SetUp() override { auto params = GetParam(); - function = CreateFunction(params); + function = CreateModel(params); for (const auto& input_tensor : params.inputs) { inputData.push_back(input_tensor.data); } @@ -52,7 +52,7 @@ public: } private: - static std::shared_ptr CreateFunction(const EinsumParams& params) { + static std::shared_ptr CreateModel(const EinsumParams& params) { OutputVector output_vector; ParameterVector param_vector; for (const auto& input_tensor : params.inputs) { @@ -61,7 +61,7 @@ private: param_vector.push_back(param); } const auto einsum = std::make_shared(output_vector, params.equation); - const auto f = std::make_shared(OutputVector{einsum}, param_vector); + const auto f = std::make_shared(OutputVector{einsum}, param_vector); return f; } }; @@ -179,4 +179,4 @@ std::vector generateCombinedParams() { INSTANTIATE_TEST_SUITE_P(smoke_Einsum_With_Hardcoded_Refs, ReferenceEinsumTest, testing::ValuesIn(generateCombinedParams()), ReferenceEinsumTest::getTestCaseName); -} // namespace \ No newline at end of file +} // namespace diff --git a/docs/template_plugin/tests/functional/op_reference/extract_image_patches.cpp b/docs/template_plugin/tests/functional/op_reference/extract_image_patches.cpp index 95f5571cc41..503880ce8ac 100644 --- a/docs/template_plugin/tests/functional/op_reference/extract_image_patches.cpp +++ b/docs/template_plugin/tests/functional/op_reference/extract_image_patches.cpp @@ -36,7 +36,7 @@ class ReferenceExtractImagePatchesTest : public testing::TestWithParam CreateFunction(const ExtractImagePatchesParams& params) { + static std::shared_ptr CreateModel(const ExtractImagePatchesParams& params) { const auto data = std::make_shared(params.data.type, params.data.shape); const auto extrace_image_patches = std::make_shared(data, params.sizes, params.strides, params.rates, params.autoPad); - const auto f = std::make_shared(extrace_image_patches, ParameterVector{data}); + const auto f = std::make_shared(extrace_image_patches, ParameterVector{data}); return f; } }; @@ -243,4 +243,4 @@ std::vector generateCombinedParams() { INSTANTIATE_TEST_SUITE_P(smoke_ExtractImagePatches_With_Hardcoded_Refs, ReferenceExtractImagePatchesTest, testing::ValuesIn(generateCombinedParams()), ReferenceExtractImagePatchesTest::getTestCaseName); -} // namespace \ No newline at end of file +} // namespace From 9b71a5fb704acc7f3360c1c7b80b1905737cada2 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 16 Dec 2021 07:52:59 +0300 Subject: [PATCH 6/7] Fixed python tests (#9238) --- src/bindings/python/tests/test_utils/test_utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bindings/python/tests/test_utils/test_utils.py b/src/bindings/python/tests/test_utils/test_utils.py index b312689aaa7..d8364635813 100644 --- a/src/bindings/python/tests/test_utils/test_utils.py +++ b/src/bindings/python/tests/test_utils/test_utils.py @@ -1,9 +1,9 @@ # Copyright (C) 2021 Intel Corporation # SPDX-License-Identifier: Apache-2.0 -from openvino.runtime import Function -from openvino.runtime.impl import Shape, Type -from openvino.runtime.impl.op import Parameter +from openvino.runtime import Model +from openvino.runtime import Shape, Type +from openvino.runtime.op import Parameter import openvino.runtime.opset8 as ops @@ -11,7 +11,7 @@ def get_test_function(): element_type = Type.f32 param = Parameter(element_type, Shape([1, 3, 22, 22])) relu = ops.relu(param) - func = Function([relu], [param], "test") + func = Model([relu], [param], "test") assert func is not None return func From ea3f34c3516775724d61f926d44eeea49ecc6421 Mon Sep 17 00:00:00 2001 From: Indira Salyahova Date: Thu, 16 Dec 2021 08:51:24 +0300 Subject: [PATCH 7/7] Temporary revert test layout (#9242) * Update test_image_loading.py * Update test_image_loading.py --- tools/pot/tests/test_image_loading.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/pot/tests/test_image_loading.py b/tools/pot/tests/test_image_loading.py index ff82d73c3d6..fc520c19d48 100644 --- a/tools/pot/tests/test_image_loading.py +++ b/tools/pot/tests/test_image_loading.py @@ -46,15 +46,17 @@ def test_check_image(tmp_path, models, model_name, model_framework): assert num_images_from_data_loader == num_images_in_dir -TEST_MODELS_LAYOUT = [('mobilenet-v2-pytorch', 'pytorch', 'NCHW', (3, 224, 224)), - ('mobilenet-v2-pytorch', 'pytorch', 'NHWC', (224, 224, 3)), - ('mobilenet-v2-pytorch', 'pytorch', None, (3, 224, 224)), - ('mobilenet-v1-1.0-224-tf', 'tf', None, (224, 224, 3))] +TEST_MODELS_LAYOUT = [ + #('mobilenet-v2-pytorch', 'pytorch', 'NCHW', (3, 224, 224)), + #('mobilenet-v2-pytorch', 'pytorch', 'NHWC', (224, 224, 3)), + #('mobilenet-v2-pytorch', 'pytorch', None, (3, 224, 224)), + #('mobilenet-v1-1.0-224-tf', 'tf', None, (224, 224, 3)) +] @pytest.mark.parametrize( - 'model_name, model_framework, layout, reference_shape', TEST_MODELS, - ids=['{}_{}'.format(m[0], m[1]) for m in TEST_MODELS]) + 'model_name, model_framework, layout, reference_shape', TEST_MODELS_LAYOUT, + ids=['{}_{}_{}_{}'.format(m[0], m[1], m[2], m[3]) for m in TEST_MODELS_LAYOUT]) def test_check_layout(tmp_path, models, model_name, model_framework, layout, reference_shape): test_dir = Path(__file__).parent path_image_data = os.path.join(test_dir, "data/image_data")