-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use ONNX Frontend instead of ONNX Reader #7031
Changes from all commits
9ec27f5
67cfdd4
cf64e13
714d444
90cd973
d8a4e22
2129dae
aa5bb21
9264675
3f5c55e
51b31c7
f16c67a
1de22dd
f4a4bab
4ca5317
48ad76a
adfd5ab
c5b90ed
b66e61c
cad333b
563afaa
a8aabaf
7eda63e
7e9c2bd
e8b8432
a7de4c9
8112b7d
b295719
3e80a35
422e757
0f0717c
7f8c848
bfa4267
ccfb492
f78d3bc
2728690
a93a14b
44b7642
9aab1cb
3f4edbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,11 @@ namespace { | |
// Extension to plugins creator | ||
std::multimap<std::string, Reader::Ptr> readers; | ||
|
||
static ngraph::frontend::FrontEndManager* get_frontend_manager() { | ||
static ngraph::frontend::FrontEndManager manager; | ||
return &manager; | ||
} | ||
|
||
void registerReaders() { | ||
OV_ITT_SCOPED_TASK(ov::itt::domains::IE, "registerReaders"); | ||
static bool initialized = false; | ||
|
@@ -115,14 +120,6 @@ void registerReaders() { | |
return std::make_shared<Reader>(name, library_name); | ||
}; | ||
|
||
// try to load ONNX reader if library exists | ||
auto onnxReader = | ||
create_if_exists("ONNX", std::string("inference_engine_onnx_reader") + std::string(IE_BUILD_POSTFIX)); | ||
if (onnxReader) { | ||
readers.emplace("onnx", onnxReader); | ||
readers.emplace("prototxt", onnxReader); | ||
} | ||
|
||
// try to load IR reader v10 if library exists | ||
auto irReaderv10 = | ||
create_if_exists("IRv10", std::string("inference_engine_ir_reader") + std::string(IE_BUILD_POSTFIX)); | ||
|
@@ -174,10 +171,6 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, | |
#endif | ||
// Try to open model file | ||
std::ifstream modelStream(model_path, std::ios::binary); | ||
// save path in extensible array of stream | ||
// notice: lifetime of path pointed by pword(0) is limited by current scope | ||
const std::string path_to_save_in_stream = modelPath; | ||
modelStream.pword(0) = const_cast<char*>(path_to_save_in_stream.c_str()); | ||
if (!modelStream.is_open()) | ||
IE_THROW() << "Model file " << modelPath << " cannot be opened!"; | ||
|
||
|
@@ -240,7 +233,7 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, | |
} | ||
} | ||
// Try to load with FrontEndManager | ||
static ngraph::frontend::FrontEndManager manager; | ||
const auto manager = get_frontend_manager(); | ||
ngraph::frontend::FrontEnd::Ptr FE; | ||
ngraph::frontend::InputModel::Ptr inputModel; | ||
if (!binPath.empty()) { | ||
|
@@ -249,17 +242,17 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, | |
#else | ||
std::string weights_path = binPath; | ||
#endif | ||
FE = manager.load_by_model(model_path, weights_path); | ||
FE = manager->load_by_model(model_path, weights_path); | ||
if (FE) | ||
inputModel = FE->load(model_path, weights_path); | ||
} else { | ||
FE = manager.load_by_model(model_path); | ||
FE = manager->load_by_model(model_path); | ||
if (FE) | ||
inputModel = FE->load(model_path); | ||
} | ||
if (inputModel) { | ||
auto ngFunc = FE->convert(inputModel); | ||
return CNNNetwork(ngFunc); | ||
return CNNNetwork(ngFunc, exts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we have a scenario
|
||
} | ||
IE_THROW() << "Unknown model format! Cannot find reader for model format: " << fileExt | ||
<< " and read the model: " << modelPath << ". Please check that reader library exists in your PATH."; | ||
|
@@ -282,6 +275,19 @@ CNNNetwork details::ReadNetwork(const std::string& model, | |
return reader->read(modelStream, exts); | ||
} | ||
} | ||
// Try to load with FrontEndManager | ||
// NOTE: weights argument is ignored | ||
const auto manager = get_frontend_manager(); | ||
ngraph::frontend::FrontEnd::Ptr FE; | ||
ngraph::frontend::InputModel::Ptr inputModel; | ||
FE = manager->load_by_model(&modelStream); | ||
if (FE) | ||
inputModel = FE->load(&modelStream); | ||
if (inputModel) { | ||
auto ngFunc = FE->convert(inputModel); | ||
return CNNNetwork(ngFunc, exts); | ||
} | ||
|
||
IE_THROW() << "Unknown model format! Cannot find reader for the model and read it. Please check that reader " | ||
"library exists in your PATH."; | ||
} | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline to resolve it separately