[ONNX] Refactoring tests on API 2.0 (#21596)
* Applied common functions to tests in conversion.cpp * Refactored convert_partially_tests * Refactored convert_tests.cpp * Removed usage of ngraph namespace in load_from.cpp * Replaced definition in model_support_tests.cpp * Fixed codestyle
This commit is contained in:
1 parent
f094ef81f0
commit
88c8143dd8
5 files changed
+32
-79
No files matched your search
@@ -65,14 +65,8 @@ TEST(ONNXConversionExtensionTest, custom_op_with_custom_domain) {
|
||||
return {op};
|
||||
});
|
||||
|
||||
auto fe = std::make_shared<ov::frontend::onnx::FrontEnd>();
|
||||
fe->add_extension(ext);
|
||||
|
||||
const auto input_model = fe->load(ov::test::utils::getModelFromTestModelZoo(
|
||||
ov::util::path_join({TEST_ONNX_MODELS_DIRNAME, "missing_op_domain.onnx"})));
|
||||
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_NO_THROW(model = fe->convert(input_model));
|
||||
ASSERT_NO_THROW(model = onnx::tests::convert_model("missing_op_domain.onnx", ext));
|
||||
|
||||
for (const auto& op : model->get_ops()) {
|
||||
if (const auto& add = std::dynamic_pointer_cast<ov::op::v1::Add>(op)) {
|
||||
@@ -93,12 +87,6 @@ TEST(ONNXConversionExtensionTest, custom_op_with_incorrect_numer_of_outputs_exce
|
||||
return {op};
|
||||
});
|
||||
|
||||
auto fe = std::make_shared<ov::frontend::onnx::FrontEnd>();
|
||||
fe->add_extension(ext);
|
||||
|
||||
const auto input_model = fe->load(ov::test::utils::getModelFromTestModelZoo(
|
||||
ov::util::path_join({TEST_ONNX_MODELS_DIRNAME, "missing_op_domain.onnx"})));
|
||||
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_THROW(fe->convert(input_model), ov::Exception);
|
||||
ASSERT_THROW(onnx::tests::convert_model("missing_op_domain.onnx", ext), ov::Exception);
|
||||
}
|
||||
@@ -8,18 +8,14 @@
|
||||
|
||||
#include "common_test_utils/file_utils.hpp"
|
||||
#include "common_test_utils/ov_test_utils.hpp"
|
||||
#include "onnx_utils.hpp"
|
||||
#include "openvino/frontend/manager.hpp"
|
||||
#include "openvino/op/util/framework_node.hpp"
|
||||
#include "openvino/opsets/opset11.hpp"
|
||||
|
||||
namespace {
|
||||
std::shared_ptr<ov::Model> convert_partially(const std::string& path) {
|
||||
ov::frontend::FrontEndManager manager;
|
||||
const auto frontend = manager.load_by_framework("onnx");
|
||||
const auto in_model = frontend->load(path);
|
||||
return frontend->convert_partially(in_model);
|
||||
}
|
||||
using namespace ov::frontend::onnx::tests;
|
||||
|
||||
namespace {
|
||||
std::shared_ptr<ov::op::util::FrameworkNode> get_framework_node_with_out_name(const std::shared_ptr<ov::Model>& model,
|
||||
const std::string& out_name) {
|
||||
for (const auto& op : model->get_ops()) {
|
||||
@@ -36,10 +32,8 @@ std::shared_ptr<ov::op::util::FrameworkNode> get_framework_node_with_out_name(co
|
||||
} // namespace
|
||||
|
||||
TEST(ONNXFeConvertPartially, insert_framework_node_if_unsupported) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) +
|
||||
"unsupported_ops/add_unsupported.onnx");
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_NO_THROW(model = convert_partially(path));
|
||||
ASSERT_NO_THROW(model = convert_partially("unsupported_ops/add_unsupported.onnx"));
|
||||
ASSERT_TRUE(model);
|
||||
|
||||
EXPECT_EQ(count_ops_of_type<ov::opset11::Add>(model), 1);
|
||||
@@ -50,10 +44,8 @@ TEST(ONNXFeConvertPartially, insert_framework_node_if_unsupported) {
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertPartially, insert_more_framework_nodes_if_unsupported) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) +
|
||||
"unsupported_ops/two_unsupported_nodes.onnx");
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_NO_THROW(model = convert_partially(path));
|
||||
ASSERT_NO_THROW(model = convert_partially("unsupported_ops/two_unsupported_nodes.onnx"));
|
||||
ASSERT_TRUE(model);
|
||||
|
||||
EXPECT_EQ(count_ops_of_type<ov::opset11::Add>(model), 1);
|
||||
@@ -68,10 +60,8 @@ TEST(ONNXFeConvertPartially, insert_more_framework_nodes_if_unsupported) {
|
||||
|
||||
// validation error - onnx/instance_norm_bad_scale_type.onnx
|
||||
TEST(ONNXFeConvertPartially, insert_framework_node_if_onnx_validation_exception) {
|
||||
const auto path =
|
||||
ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) + "instance_norm_bad_scale_type.onnx");
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_NO_THROW(model = convert_partially(path));
|
||||
ASSERT_NO_THROW(model = convert_partially("instance_norm_bad_scale_type.onnx"));
|
||||
ASSERT_TRUE(model);
|
||||
|
||||
const auto incorrect_instance_norm = get_framework_node_with_out_name(model, "y");
|
||||
@@ -80,10 +70,8 @@ TEST(ONNXFeConvertPartially, insert_framework_node_if_onnx_validation_exception)
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertPartially, insert_framework_node_if_other_translation_exception) {
|
||||
const auto path =
|
||||
ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) + "depth_to_space_bad_mode.onnx");
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_NO_THROW(model = convert_partially(path));
|
||||
ASSERT_NO_THROW(model = convert_partially("depth_to_space_bad_mode.onnx"));
|
||||
ASSERT_TRUE(model);
|
||||
|
||||
const auto incorrect_dts = get_framework_node_with_out_name(model, "B");
|
||||
@@ -92,10 +80,8 @@ TEST(ONNXFeConvertPartially, insert_framework_node_if_other_translation_exceptio
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertPartially, insert_framework_nodes_if_both_unsupported_and_other_translation_exception) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(
|
||||
std::string(ONNX_TEST_MODELS) + "unsupported_ops/unsupported_add_and_incorrect_dts.onnx");
|
||||
std::shared_ptr<ov::Model> model;
|
||||
ASSERT_NO_THROW(model = convert_partially(path));
|
||||
ASSERT_NO_THROW(model = convert_partially("unsupported_ops/unsupported_add_and_incorrect_dts.onnx"));
|
||||
ASSERT_TRUE(model);
|
||||
|
||||
EXPECT_EQ(count_ops_of_type<ov::opset11::Abs>(model), 1);
|
||||
|
||||
@@ -8,73 +8,57 @@
|
||||
|
||||
#include "common_test_utils/file_utils.hpp"
|
||||
#include "common_test_utils/test_assertions.hpp"
|
||||
#include "onnx_utils.hpp"
|
||||
#include "openvino/frontend/manager.hpp"
|
||||
|
||||
namespace {
|
||||
void convert(const std::string& path) {
|
||||
ov::frontend::FrontEndManager manager;
|
||||
const auto frontend = manager.load_by_framework("onnx");
|
||||
const auto in_model = frontend->load(path);
|
||||
frontend->convert(in_model);
|
||||
}
|
||||
} // namespace
|
||||
using namespace ov::frontend::onnx::tests;
|
||||
|
||||
TEST(ONNXFeConvertException, exception_if_node_unsupported) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) +
|
||||
"unsupported_ops/add_unsupported.onnx");
|
||||
|
||||
OV_EXPECT_THROW(
|
||||
convert(path),
|
||||
convert_model("unsupported_ops/add_unsupported.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::EndsWith("OpenVINO does not support the following ONNX operations: test_domain.UnsupportedAdd\n"));
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertException, exception_if_more_nodes_unsupported) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) +
|
||||
"unsupported_ops/two_unsupported_nodes.onnx");
|
||||
|
||||
OV_EXPECT_THROW(
|
||||
convert(path),
|
||||
convert_model("unsupported_ops/two_unsupported_nodes.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::EndsWith("OpenVINO does not support the following ONNX operations: UnsupportedAbs, UnsupportedAdd\n"));
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertException, exception_if_onnx_validation_exception) {
|
||||
const auto path =
|
||||
ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) + "instance_norm_bad_scale_type.onnx");
|
||||
|
||||
OV_EXPECT_THROW(convert(path),
|
||||
OV_EXPECT_THROW(convert_model("instance_norm_bad_scale_type.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::EndsWith("Element types for data and scale input do not match (data element type: f32, "
|
||||
"scale element type: u16).\n"));
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertException, exception_if_other_translation_exception) {
|
||||
const auto path =
|
||||
ov::test::utils::getModelFromTestModelZoo(std::string(ONNX_TEST_MODELS) + "depth_to_space_bad_mode.onnx");
|
||||
|
||||
OV_EXPECT_THROW(convert(path), ov::AssertFailure, testing::EndsWith("only 'DCR' and 'CRD' modes are supported\n"));
|
||||
OV_EXPECT_THROW(convert_model("depth_to_space_bad_mode.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::EndsWith("only 'DCR' and 'CRD' modes are supported\n"));
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertException, exception_if_both_unsupported_and_other_translation_exception) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(
|
||||
std::string(ONNX_TEST_MODELS) + "unsupported_ops/unsupported_add_and_incorrect_dts.onnx");
|
||||
|
||||
OV_EXPECT_THROW(
|
||||
convert(path),
|
||||
convert_model("unsupported_ops/unsupported_add_and_incorrect_dts.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::HasSubstr("OpenVINO does not support the following ONNX operations: test_domain.UnsupportedAdd"));
|
||||
OV_EXPECT_THROW(convert(path), ov::AssertFailure, testing::EndsWith("only 'DCR' and 'CRD' modes are supported\n"));
|
||||
OV_EXPECT_THROW(convert_model("unsupported_ops/unsupported_add_and_incorrect_dts.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::EndsWith("only 'DCR' and 'CRD' modes are supported\n"));
|
||||
}
|
||||
|
||||
TEST(ONNXFeConvertException, exception_if_both_unsupported_onnx_validation_exception_and_other_exception) {
|
||||
const auto path = ov::test::utils::getModelFromTestModelZoo(
|
||||
std::string(ONNX_TEST_MODELS) + "unsupported_ops/unsupported_add_incorrect_dts_and_inst_norm_bad_scale.onnx");
|
||||
|
||||
OV_EXPECT_THROW(
|
||||
convert(path),
|
||||
convert_model("unsupported_ops/unsupported_add_incorrect_dts_and_inst_norm_bad_scale.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::HasSubstr("OpenVINO does not support the following ONNX operations: test_domain.UnsupportedAdd"));
|
||||
OV_EXPECT_THROW(convert(path), ov::AssertFailure, testing::HasSubstr("'stop' input is not a scalar"));
|
||||
OV_EXPECT_THROW(convert(path), ov::AssertFailure, testing::EndsWith("only 'DCR' and 'CRD' modes are supported\n"));
|
||||
OV_EXPECT_THROW(convert_model("unsupported_ops/unsupported_add_incorrect_dts_and_inst_norm_bad_scale.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::HasSubstr("'stop' input is not a scalar"));
|
||||
OV_EXPECT_THROW(convert_model("unsupported_ops/unsupported_add_incorrect_dts_and_inst_norm_bad_scale.onnx"),
|
||||
ov::AssertFailure,
|
||||
testing::EndsWith("only 'DCR' and 'CRD' modes are supported\n"));
|
||||
}
|
||||
@@ -6,12 +6,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <fstream>
|
||||
#include <ngraph/file_util.hpp>
|
||||
|
||||
#include "onnx_utils.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using namespace ngraph;
|
||||
using namespace ov::frontend;
|
||||
|
||||
using ONNXLoadTest = FrontEndLoadFromTest;
|
||||
@@ -26,11 +24,8 @@ static LoadFromFEParam getTestData() {
|
||||
}
|
||||
|
||||
TEST_P(FrontEndLoadFromTest, testLoadFromStreamAndPassPath) {
|
||||
NGRAPH_SUPPRESS_DEPRECATED_START
|
||||
const auto path = file_util::path_join(ov::test::utils::getExecutableDirectory(),
|
||||
TEST_ONNX_MODELS_DIRNAME,
|
||||
"external_data/external_data.onnx");
|
||||
NGRAPH_SUPPRESS_DEPRECATED_END
|
||||
const auto path = ov::util::path_join(
|
||||
{ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, "external_data/external_data.onnx"});
|
||||
std::ifstream ifs(path, std::ios::in | std::ios::binary);
|
||||
ASSERT_TRUE(ifs.is_open()) << "Could not open an ifstream for the model path: " << path;
|
||||
std::istream* is = &ifs;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace {
|
||||
std::string model_path(const char* model) {
|
||||
std::string path = ONNX_TEST_MODELS;
|
||||
std::string path = TEST_ONNX_MODELS_DIRNAME;
|
||||
path += "support_test/";
|
||||
path += model;
|
||||
return ov::test::utils::getModelFromTestModelZoo(path);
|
||||
|
||||
Reference in new issue
Block a user