diff --git a/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp b/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp index 47de95df993..7b8a36ad209 100644 --- a/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp +++ b/src/frontends/onnx/tests/onnx_editor_topological_sort.cpp @@ -9,84 +9,84 @@ #include "common_test_utils/test_control.hpp" #include "editor.hpp" #include "gtest/gtest.h" -#include "ngraph/file_util.hpp" #include "onnx_test_util.hpp" +#include "onnx_utils.hpp" using namespace ov; using namespace ov::onnx_editor; -using namespace ngraph::test; +using namespace ov::frontend::onnx::tests; -static std::string s_manifest = ngraph::file_util::path_join(ov::test::utils::getExecutableDirectory(), "${MANIFEST}"); +static std::string s_manifest = onnx_backend_manifest("${MANIFEST}"); OPENVINO_TEST(onnx_editor, topological_sort_two_nodes_swap) { ONNXModelEditor editor{ov::util::path_join({ov::test::utils::getExecutableDirectory(), - SERIALIZED_ZOO, - "onnx/model_editor/topological_sort/two_nodes_swap.onnx"})}; + TEST_ONNX_MODELS_DIRNAME, + "model_editor/topological_sort/two_nodes_swap.onnx"})}; ASSERT_NO_THROW(editor.get_function()); } OPENVINO_TEST(onnx_editor, topological_sort_completely_unsorted) { ONNXModelEditor editor{ov::util::path_join({ov::test::utils::getExecutableDirectory(), - SERIALIZED_ZOO, - "onnx/model_editor/topological_sort/completely_unsorted.onnx"})}; + TEST_ONNX_MODELS_DIRNAME, + "model_editor/topological_sort/completely_unsorted.onnx"})}; ASSERT_NO_THROW(editor.get_function()); } OPENVINO_TEST(onnx_editor, topological_sort_completely_unsorted_2) { ONNXModelEditor editor{ov::util::path_join({ov::test::utils::getExecutableDirectory(), - SERIALIZED_ZOO, - "onnx/model_editor/topological_sort/completely_unsorted_2.onnx"})}; + TEST_ONNX_MODELS_DIRNAME, + "model_editor/topological_sort/completely_unsorted_2.onnx"})}; ASSERT_NO_THROW(editor.get_function()); } #if defined(OPENVINO_ENABLE_UNICODE_PATH_SUPPORT) && defined(_WIN32) OPENVINO_TEST(onnx_editor, topological_sort_completely_unsorted_2_wstring) { - ONNXModelEditor editor{ov::util::string_to_wstring( - ov::util::path_join({ov::test::utils::getExecutableDirectory(), - SERIALIZED_ZOO, - "onnx/model_editor/topological_sort/completely_unsorted_2.onnx"}))}; + ONNXModelEditor editor{ + ov::util::string_to_wstring(ov::util::path_join({ov::test::utils::getExecutableDirectory(), + TEST_ONNX_MODELS_DIRNAME, + "model_editor/topological_sort/completely_unsorted_2.onnx"}))}; ASSERT_NO_THROW(editor.get_function()); } #endif OPENVINO_TEST(onnx_editor, topological_sort_constant_node_in_the_graph) { - const std::string rel_path_to_model = "onnx/model_editor/topological_sort/add_abc_const_node_unsorted.onnx"; + const std::string rel_path_to_model = "model_editor/topological_sort/add_abc_const_node_unsorted.onnx"; ONNXModelEditor editor{ - ov::util::path_join({ov::test::utils::getExecutableDirectory(), SERIALIZED_ZOO, rel_path_to_model})}; + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, rel_path_to_model})}; ASSERT_NO_THROW(editor.get_function()); } OPENVINO_TEST(onnx_editor, topological_sort_multioutput_node) { - const std::string rel_path_to_model = "onnx/model_editor/topological_sort/multioutput_split_unsorted.onnx"; + const std::string rel_path_to_model = "model_editor/topological_sort/multioutput_split_unsorted.onnx"; ONNXModelEditor editor{ - ov::util::path_join({ov::test::utils::getExecutableDirectory(), SERIALIZED_ZOO, rel_path_to_model})}; + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, rel_path_to_model})}; ASSERT_NO_THROW(editor.get_function()); } OPENVINO_TEST(onnx_editor, topological_sort_graph_not_changed_if_the_same_name_of_unsorted_node_and_initializer) { const std::string rel_path_to_model = - "onnx/model_editor/topological_sort/same_name_of_unsorted_node_and_initializer.onnx"; + "model_editor/topological_sort/same_name_of_unsorted_node_and_initializer.onnx"; ONNXModelEditor editor{ - ov::util::path_join({ov::test::utils::getExecutableDirectory(), SERIALIZED_ZOO, rel_path_to_model})}; + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, rel_path_to_model})}; // topological sorting is called only via Editor importing const auto ref_model = - ov::util::path_join({ov::test::utils::getExecutableDirectory(), SERIALIZED_ZOO, rel_path_to_model}); + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, rel_path_to_model}); const auto result = compare_onnx_models(editor.model_string(), ref_model); EXPECT_TRUE(result.is_ok) << result.error_message; } OPENVINO_TEST(onnx_editor, topological_sort_graph_not_changed_if_empty_input_name) { - const std::string rel_path_to_model = "onnx/model_editor/topological_sort/empty_input_name.onnx"; + const std::string rel_path_to_model = "model_editor/topological_sort/empty_input_name.onnx"; ONNXModelEditor editor{ - ov::util::path_join({ov::test::utils::getExecutableDirectory(), SERIALIZED_ZOO, rel_path_to_model})}; + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, rel_path_to_model})}; // topological sorting is called only via Editor importing const auto ref_model = - ov::util::path_join({ov::test::utils::getExecutableDirectory(), SERIALIZED_ZOO, rel_path_to_model}); + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, rel_path_to_model}); const auto result = compare_onnx_models(editor.model_string(), ref_model); EXPECT_TRUE(result.is_ok) << result.error_message; diff --git a/src/frontends/onnx/tests/onnx_importer_test.cpp b/src/frontends/onnx/tests/onnx_importer_test.cpp index 83e728e0ada..b2cda145731 100644 --- a/src/frontends/onnx/tests/onnx_importer_test.cpp +++ b/src/frontends/onnx/tests/onnx_importer_test.cpp @@ -9,132 +9,120 @@ #include #include "common_test_utils/file_utils.hpp" -#include "onnx_import/onnx.hpp" +#include "onnx_utils.hpp" #include "openvino/openvino.hpp" #include "openvino/util/file_util.hpp" -OPENVINO_SUPPRESS_DEPRECATED_START +using namespace ov; +using namespace ov::frontend::onnx::tests; TEST(ONNX_Importer_Tests, ImportBasicModel) { - auto model_file_path = - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "add_abc_initializers.onnx"})); - auto function = ngraph::onnx_import::import_onnx_model(model_file_path); + auto model = convert_model("add_abc_initializers.onnx"); int count_additions = 0; int count_constants = 0; int count_parameters = 0; - for (auto op : function->get_ops()) { + for (auto op : model->get_ops()) { const auto op_type = std::string(op->get_type_name()); count_additions += (op_type == "Add" ? 1 : 0); count_constants += (op_type == "Constant" ? 1 : 0); count_parameters += (op_type == "Parameter" ? 1 : 0); } - ASSERT_EQ(function->get_output_size(), 1); - ASSERT_EQ(std::string(function->get_output_op(0)->get_type_name()), "Result"); - ASSERT_EQ(function->get_output_element_type(0), ngraph::element::f32); - ASSERT_EQ(function->get_output_shape(0), ngraph::Shape({2, 2})); + ASSERT_EQ(model->get_output_size(), 1); + ASSERT_EQ(std::string(model->get_output_op(0)->get_type_name()), "Result"); + ASSERT_EQ(model->get_output_element_type(0), element::f32); + ASSERT_EQ(model->get_output_shape(0), Shape({2, 2})); ASSERT_EQ(count_additions, 2); ASSERT_EQ(count_constants, 2); ASSERT_EQ(count_parameters, 1); } TEST(ONNX_Importer_Tests, ImportModelWithFusedOp) { - auto model_file_path = - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "selu.onnx"})); - auto function = ngraph::onnx_import::import_onnx_model(model_file_path); + auto model = convert_model("selu.onnx"); int count_selu = 0; int count_constants = 0; int count_parameters = 0; - for (auto op : function->get_ops()) { + for (auto op : model->get_ops()) { const auto op_type = std::string(op->get_type_name()); count_selu += (op_type == "Selu" ? 1 : 0); count_constants += (op_type == "Constant" ? 1 : 0); count_parameters += (op_type == "Parameter" ? 1 : 0); } - ASSERT_EQ(function->get_output_size(), 1); - ASSERT_EQ(std::string(function->get_output_op(0)->get_type_name()), "Result"); - ASSERT_EQ(function->get_output_element_type(0), ngraph::element::f32); - ASSERT_EQ(function->get_output_shape(0), ngraph::Shape({3, 4, 5})); + ASSERT_EQ(model->get_output_size(), 1); + ASSERT_EQ(std::string(model->get_output_op(0)->get_type_name()), "Result"); + ASSERT_EQ(model->get_output_element_type(0), element::f32); + ASSERT_EQ(model->get_output_shape(0), Shape({3, 4, 5})); ASSERT_EQ(count_selu, 1); ASSERT_EQ(count_constants, 2); ASSERT_EQ(count_parameters, 1); } TEST(ONNX_Importer_Tests, ImportModelWithMultiOutput) { - auto model_file_path = - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "topk.onnx"})); - auto function = ngraph::onnx_import::import_onnx_model(model_file_path); + auto model = convert_model("topk.onnx"); int count_topk = 0; int count_constants = 0; int count_parameters = 0; - for (auto op : function->get_ops()) { + for (auto op : model->get_ops()) { const auto op_type = std::string(op->get_type_name()); count_topk += (op_type == "TopK" ? 1 : 0); count_constants += (op_type == "Constant" ? 1 : 0); count_parameters += (op_type == "Parameter" ? 1 : 0); } - ASSERT_EQ(function->get_output_size(), 2); - ASSERT_EQ(std::string(function->get_output_op(0)->get_type_name()), "Result"); - ASSERT_EQ(std::string(function->get_output_op(1)->get_type_name()), "Result"); - ASSERT_EQ(function->get_output_element_type(0), ngraph::element::f32); - ASSERT_EQ(function->get_output_element_type(1), ngraph::element::i64); - ASSERT_EQ(function->get_output_shape(0), ngraph::Shape({3, 3})); - ASSERT_EQ(function->get_output_shape(1), ngraph::Shape({3, 3})); + ASSERT_EQ(model->get_output_size(), 2); + ASSERT_EQ(std::string(model->get_output_op(0)->get_type_name()), "Result"); + ASSERT_EQ(std::string(model->get_output_op(1)->get_type_name()), "Result"); + ASSERT_EQ(model->get_output_element_type(0), element::f32); + ASSERT_EQ(model->get_output_element_type(1), element::i64); + ASSERT_EQ(model->get_output_shape(0), Shape({3, 3})); + ASSERT_EQ(model->get_output_shape(1), Shape({3, 3})); ASSERT_EQ(count_topk, 1); ASSERT_EQ(count_constants, 1); ASSERT_EQ(count_parameters, 1); } TEST(ONNX_Importer_Tests, ImportModelWithNotSupportedOp) { - auto model_file_path = - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "not_supported.onnx"})); try { - auto function = ngraph::onnx_import::import_onnx_model(model_file_path); + auto model = convert_model("not_supported.onnx"); FAIL() << "Any expection was thrown despite the ONNX model is not supported"; - } catch (const ngraph::ngraph_error& error) { + } catch (const Exception& error) { EXPECT_PRED_FORMAT2(testing::IsSubstring, std::string("OpenVINO does not support the following ONNX operations: NotSupported"), error.what()); } catch (...) { - FAIL() << "Expected 'ngraph::ngraph_error' exception was not thrown despite the ONNX model is not supported"; + FAIL() << "Expected 'Exception' exception was not thrown despite the ONNX model is not supported"; } } TEST(ONNX_Importer_Tests, ImportModelWhenFileDoesNotExist) { - auto model_file_path = - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "not_exist_file.onnx"})); try { - auto function = ngraph::onnx_import::import_onnx_model(model_file_path); + auto model = convert_model("not_exist_file.onnx"); FAIL() << "Any expection was thrown despite the ONNX model file does not exist"; - } catch (const ngraph::ngraph_error& error) { - EXPECT_PRED_FORMAT2(testing::IsSubstring, - std::string("Error during import of ONNX model expected to be in file:"), - error.what()); + } catch (const Exception& error) { + EXPECT_PRED_FORMAT2(testing::IsSubstring, std::string("Could not open the file"), error.what()); } catch (...) { - FAIL() << "Expected 'ngraph::ngraph_error' exception was not thrown despite the ONNX model file does not exist"; + FAIL() << "Expected 'Exception' exception was not thrown despite the ONNX model file does not exist"; } } -// TODO: CVS-61224 -TEST(ONNX_Importer_Tests, DISABLED_ImportModelFromStream) { +TEST(ONNX_Importer_Tests, ImportModelFromStream) { auto model_file_path = - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "addmul_abc.onnx"})); - std::ifstream model_file_stream(model_file_path); + test::utils::getModelFromTestModelZoo(util::path_join({TEST_ONNX_MODELS_DIRNAME, "addmul_abc.onnx"})); + std::ifstream model_file_stream(model_file_path, std::ifstream::binary); ASSERT_TRUE(model_file_stream.is_open()); int count_adds = 0; int count_multiplies = 0; int count_parameters = 0; - auto function = ngraph::onnx_import::import_onnx_model(model_file_stream); - for (auto op : function->get_ops()) { + auto model = convert_model(model_file_stream); + for (auto op : model->get_ops()) { const auto op_type = std::string(op->get_type_name()); count_adds += (op_type == "Add" ? 1 : 0); count_multiplies += (op_type == "Multiply" ? 1 : 0); @@ -145,39 +133,21 @@ TEST(ONNX_Importer_Tests, DISABLED_ImportModelFromStream) { ASSERT_EQ(count_parameters, 3); } -TEST(ONNX_Importer_Tests, GetSupportedOperators) { - const std::int64_t version = 1; - const std::string domain = "ai.onnx"; - const std::set supported_ops = ngraph::onnx_import::get_supported_operators(version, domain); - - ASSERT_GT(supported_ops.size(), 1); - ASSERT_TRUE(supported_ops.find("Add") != supported_ops.end()); -} - -TEST(ONNX_Importer_Tests, IsOperatorSupported) { - const std::string op_name = "Abs"; - const std::int64_t version = 12; - const std::string domain = "ai.onnx"; - const bool is_abs_op_supported = ngraph::onnx_import::is_operator_supported(op_name, version, domain); - - ASSERT_TRUE(is_abs_op_supported); -} - TEST(ONNX_Importer_Tests, ImportModelWithoutMetadata) { - ov::Core core; + Core core; auto model = core.read_model( - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "priorbox_clustered.onnx"}))); + test::utils::getModelFromTestModelZoo(util::path_join({TEST_ONNX_MODELS_DIRNAME, "priorbox_clustered.onnx"}))); ASSERT_FALSE(model->has_rt_info("framework")); } TEST(ONNX_Importer_Tests, ImportModelWithMetadata) { - ov::Core core; + Core core; auto model = core.read_model( - ov::test::utils::getModelFromTestModelZoo(ov::util::path_join({ONNX_MODELS_DIR, "model_with_metadata.onnx"}))); + test::utils::getModelFromTestModelZoo(util::path_join({TEST_ONNX_MODELS_DIRNAME, "model_with_metadata.onnx"}))); ASSERT_TRUE(model->has_rt_info("framework")); const auto rtinfo = model->get_rt_info(); - auto metadata = rtinfo.at("framework").as(); + auto metadata = rtinfo.at("framework").as(); ASSERT_EQ(metadata.size(), 2); ASSERT_EQ(metadata["meta_key1"].as(), "meta_value1");