From ec8e6cf421e619d74d2ddbf7b8e4f83335cae13c Mon Sep 17 00:00:00 2001 From: Georgy Krivoruchko Date: Wed, 21 Aug 2024 11:26:58 +0400 Subject: [PATCH] Extended list of accepted types and some debug messages --- src/frontends/onnx/frontend/src/frontend.cpp | 23 ++++++++ src/frontends/onnx/tests/load_from.cpp | 61 ++++++++++++++++++-- 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/src/frontends/onnx/frontend/src/frontend.cpp b/src/frontends/onnx/frontend/src/frontend.cpp index 90e0ecdd2cf34c..086c5bdc0d74a5 100644 --- a/src/frontends/onnx/frontend/src/frontend.cpp +++ b/src/frontends/onnx/frontend/src/frontend.cpp @@ -86,8 +86,22 @@ InputModel::Ptr FrontEnd::load_impl(const std::vector& variants) const return std::make_shared(*stream, enable_mmap, m_extensions); } if (variants[0].is()) { + std::cerr << "shared_ptr has been received\n"; return std::make_shared(variants[0].as(), m_extensions); } + if (variants[0].is()) { + std::cerr << "ModelProto* has been received\n"; + return std::make_shared( + std::make_shared(*variants[0].as()), + m_extensions); + } + if (variants[0].is()) { + std::cerr << "uint64_t as a ModelProto* has been received\n"; + void* model_proto_ptr = reinterpret_cast(variants[0].as()); + return std::make_shared( + std::make_shared(*static_cast(model_proto_ptr)), + m_extensions); + } return nullptr; } @@ -219,6 +233,15 @@ bool FrontEnd::supported_impl(const std::vector& variants) const { return is_valid_model(*stream); } if (variants[0].is()) { + std::cerr << "shared_ptr is supported\n"; + return true; + } + if (variants[0].is()) { + std::cerr << "ModelProto* is supported\n"; + return true; + } + if (variants[0].is()) { + std::cerr << "uint64_t as a ModelProto* is supported\n"; return true; } return false; diff --git a/src/frontends/onnx/tests/load_from.cpp b/src/frontends/onnx/tests/load_from.cpp index 0e5ccda510401b..01625306c833e0 100644 --- a/src/frontends/onnx/tests/load_from.cpp +++ b/src/frontends/onnx/tests/load_from.cpp @@ -63,7 +63,7 @@ INSTANTIATE_TEST_SUITE_P(ONNXLoadTest, ::testing::Values(getTestData()), FrontEndLoadFromTest::getTestCaseName); -TEST_P(FrontEndLoadFromTest, testLoadFromModelProto) { +TEST_P(FrontEndLoadFromTest, testLoadFromModelProtoSharedPtr) { const auto path = ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, "abs.onnx"}); std::ifstream ifs(path, std::ios::in | std::ios::binary); @@ -76,15 +76,68 @@ TEST_P(FrontEndLoadFromTest, testLoadFromModelProto) { ASSERT_TRUE(model_proto->ParseFromIstream(&ifs)) << "Could not parse ModelProto from file: " << path; ASSERT_NO_THROW(m_frontEnd = m_fem.load_by_model(model_proto)) - << "Could not create the ONNX FE using a ModelProto object"; + << "Could not create the ONNX FE using a shared_ptr on a ModelProto object"; ASSERT_NE(m_frontEnd, nullptr); ASSERT_NO_THROW(m_inputModel = m_frontEnd->load(model_proto)) << "Could not load the model"; ASSERT_NE(m_inputModel, nullptr); } std::shared_ptr model; - ASSERT_NO_THROW(model = m_frontEnd->convert(m_inputModel)) - << "Could not convert the model to OV representation"; + ASSERT_NO_THROW(model = m_frontEnd->convert(m_inputModel)) << "Could not convert the model to OV representation"; + ASSERT_NE(model, nullptr); + + ASSERT_TRUE(model->get_ordered_ops().size() > 0); +} + +TEST_P(FrontEndLoadFromTest, testLoadFromModelProtoPtr) { + const auto path = + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, "abs.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::vector frontends; + FrontEnd::Ptr fe; + + { + auto model_proto = std::make_shared(); + ASSERT_TRUE(model_proto->ParseFromIstream(&ifs)) << "Could not parse ModelProto from file: " << path; + + ASSERT_NO_THROW(m_frontEnd = m_fem.load_by_model(model_proto.get())) + << "Could not create the ONNX FE using a pointer on ModelProto object"; + ASSERT_NE(m_frontEnd, nullptr); + ASSERT_NO_THROW(m_inputModel = m_frontEnd->load(model_proto.get())) << "Could not load the model"; + ASSERT_NE(m_inputModel, nullptr); + } + + std::shared_ptr model; + ASSERT_NO_THROW(model = m_frontEnd->convert(m_inputModel)) << "Could not convert the model to OV representation"; + ASSERT_NE(model, nullptr); + + ASSERT_TRUE(model->get_ordered_ops().size() > 0); +} + +TEST_P(FrontEndLoadFromTest, testLoadFromModelProtoUint64) { + const auto path = + ov::util::path_join({ov::test::utils::getExecutableDirectory(), TEST_ONNX_MODELS_DIRNAME, "abs.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::vector frontends; + FrontEnd::Ptr fe; + + { + auto model_proto = std::make_shared(); + ASSERT_TRUE(model_proto->ParseFromIstream(&ifs)) << "Could not parse ModelProto from file: " << path; + + uint64_t model_proto_ptr = reinterpret_cast(model_proto.get()); + + ASSERT_NO_THROW(m_frontEnd = m_fem.load_by_model(model_proto_ptr)) + << "Could not create the ONNX FE using a pointer on ModelProto object as uint64_t"; + ASSERT_NE(m_frontEnd, nullptr); + ASSERT_NO_THROW(m_inputModel = m_frontEnd->load(model_proto_ptr)) << "Could not load the model"; + ASSERT_NE(m_inputModel, nullptr); + } + + std::shared_ptr model; + ASSERT_NO_THROW(model = m_frontEnd->convert(m_inputModel)) << "Could not convert the model to OV representation"; ASSERT_NE(model, nullptr); ASSERT_TRUE(model->get_ordered_ops().size() > 0);