-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ONNX] Preparing environment for moving ONNX tests to API2.0 (#21528)
* Added common functions for onnx tests * Removed test cases which are non-related to ONNX Extended convert_model by extension * Extended test utils by convert_partially * Added model convertion using istream as input * Moved common functionality to a ov namespace * Removed unused function
- Loading branch information
Showing
9 changed files
with
180 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright (C) 2018-2023 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "onnx_utils.hpp" | ||
|
||
#include <openvino/runtime/core.hpp> | ||
#include <vector> | ||
|
||
#include "utils.hpp" | ||
|
||
using namespace std; | ||
using namespace ov; | ||
using namespace ov::frontend; | ||
|
||
// For compatibility purposes, need to remove when will be unused | ||
const std::string ONNX_FE = "onnx"; | ||
|
||
namespace ov { | ||
namespace frontend { | ||
namespace onnx { | ||
namespace tests { | ||
|
||
const std::string ONNX_FE = ::ONNX_FE; | ||
|
||
shared_ptr<Model> convert_model(const string& model_path, const ov::frontend::ConversionExtensionBase::Ptr& conv_ext) { | ||
auto fem = FrontEndManager(); | ||
FrontEnd::Ptr front_end = fem.load_by_framework(ONNX_FE); | ||
if (!front_end) { | ||
throw "ONNX FrontEnd is not initialized"; | ||
} | ||
|
||
if (conv_ext) { | ||
front_end->add_extension(conv_ext); | ||
} | ||
|
||
auto full_path = FrontEndTestUtils::make_model_path(string(TEST_ONNX_MODELS_DIRNAME) + model_path); | ||
InputModel::Ptr input_model = front_end->load(full_path); | ||
if (!input_model) { | ||
throw "Input Model is not loaded"; | ||
} | ||
|
||
shared_ptr<Model> model = front_end->convert(input_model); | ||
if (!model) { | ||
throw "Model is not converted"; | ||
} | ||
|
||
return model; | ||
} | ||
|
||
shared_ptr<Model> convert_model(ifstream& model_stream) { | ||
auto fem = FrontEndManager(); | ||
FrontEnd::Ptr front_end = fem.load_by_framework(ONNX_FE); | ||
if (!front_end) { | ||
throw "ONNX FrontEnd is not initialized"; | ||
} | ||
|
||
InputModel::Ptr input_model = front_end->load(dynamic_cast<istream*>(&model_stream)); | ||
if (!input_model) { | ||
throw "Input Model is not loaded"; | ||
} | ||
|
||
shared_ptr<Model> model = front_end->convert(input_model); | ||
if (!model) { | ||
throw "Model is not converted"; | ||
} | ||
|
||
return model; | ||
} | ||
|
||
shared_ptr<Model> convert_partially(const string& model_path) { | ||
auto fem = FrontEndManager(); | ||
FrontEnd::Ptr front_end = fem.load_by_framework(ONNX_FE); | ||
if (!front_end) { | ||
throw "ONNX FrontEnd is not initialized"; | ||
} | ||
|
||
auto full_path = FrontEndTestUtils::make_model_path(string(TEST_ONNX_MODELS_DIRNAME) + model_path); | ||
InputModel::Ptr input_model = front_end->load(full_path); | ||
if (!input_model) { | ||
throw "Input Model is not loaded"; | ||
} | ||
|
||
shared_ptr<Model> model = front_end->convert_partially(input_model); | ||
if (!model) { | ||
throw "Model is not converted"; | ||
} | ||
|
||
return model; | ||
} | ||
|
||
std::string onnx_backend_manifest(const std::string& manifest) { | ||
return ov::util::path_join({ov::test::utils::getExecutableDirectory(), manifest}); | ||
} | ||
|
||
} // namespace tests | ||
} // namespace onnx | ||
} // namespace frontend | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters