From 07264f980976312e65ff6f80bf27a733c20f44b7 Mon Sep 17 00:00:00 2001 From: MaajidKhan Date: Wed, 13 Jan 2021 17:20:24 +0530 Subject: [PATCH 1/3] Implemented ReadNetwork() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ->Using Core::ReadNetwork() method for reading and creating a CNNNework ->Since OpenVINO™ 2020.4 version, Inference Engine enables reading ONNX models via the Inference Engine Core API and there is no need to use directly the low-level ONNX* Importer API anymore. To read ONNX* models, it's recommended to use the Core::ReadNetwork() method that provide a uniform way to read models from ONNX format. Signed-off-by: MaajidKhan --- .../core/providers/openvino/backend_utils.cc | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/providers/openvino/backend_utils.cc b/onnxruntime/core/providers/openvino/backend_utils.cc index 4bfdc7e7aa9a7..c7a161de3c10c 100644 --- a/onnxruntime/core/providers/openvino/backend_utils.cc +++ b/onnxruntime/core/providers/openvino/backend_utils.cc @@ -47,11 +47,6 @@ struct static_cast_int64 { std::shared_ptr CreateCNNNetwork(const Provider_ModelProto& model_proto, const GlobalContext& global_context, const SubGraphContext& subgraph_context, std::map>& const_outputs_map) { -#if (defined OPENVINO_2020_2) || (defined OPENVINO_2020_3) - ORT_UNUSED_PARAMETER(const_outputs_map); -#endif - - std::istringstream model_stream{model_proto.SerializeAsString()}; std::shared_ptr ng_function; #ifndef NDEBUG @@ -60,6 +55,9 @@ CreateCNNNetwork(const Provider_ModelProto& model_proto, const GlobalContext& gl } #endif +#if (defined OPENVINO_2020_2) || (defined OPENVINO_2020_3) + ORT_UNUSED_PARAMETER(const_outputs_map); + std::istringstream model_stream{model_proto.SerializeAsString()}; try { ng_function = ngraph::onnx_import::import_onnx_model(model_stream); LOGS_DEFAULT(INFO) << "ONNX Import Done"; @@ -68,6 +66,20 @@ CreateCNNNetwork(const Provider_ModelProto& model_proto, const GlobalContext& gl } catch (...) { ORT_THROW(log_tag + "[OpenVINO-EP] Unknown exception while importing model to nGraph Func"); } +#else + InferenceEngine::CNNNetwork cnn_network; + const std::string model = model_proto.SerializeAsString(); + InferenceEngine::Blob::Ptr blob = {nullptr}; + try { + cnn_network = global_context.ie_core.ReadNetwork(model, blob); + LOGS_DEFAULT(INFO) << "Read network Done"; + } catch (const std::exception& exp) { + ORT_THROW(log_tag + "[OpenVINO-EP] Exception while Reading network: " + std::string(exp.what())); + } catch (...) { + ORT_THROW(log_tag + "[OpenVINO-EP] Unknown exception while Reading network"); + } + ng_function = cnn_network.getFunction(); +#endif if (global_context.device_type.find("GPU") != std::string::npos && subgraph_context.precision == InferenceEngine::Precision::FP16) { From b78f964debe0961afad1923a9a5857f051f415e1 Mon Sep 17 00:00:00 2001 From: MaajidKhan Date: Thu, 14 Jan 2021 21:21:37 +0530 Subject: [PATCH 2/3] Using the InferenceEngineException -> use InferenceEngine::details::InferenceEngineException to catch the exception for ReadNetwork() Signed-off-by: MaajidKhan --- onnxruntime/core/providers/openvino/backend_utils.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onnxruntime/core/providers/openvino/backend_utils.cc b/onnxruntime/core/providers/openvino/backend_utils.cc index c7a161de3c10c..cf7e9b2446bcb 100644 --- a/onnxruntime/core/providers/openvino/backend_utils.cc +++ b/onnxruntime/core/providers/openvino/backend_utils.cc @@ -73,8 +73,8 @@ CreateCNNNetwork(const Provider_ModelProto& model_proto, const GlobalContext& gl try { cnn_network = global_context.ie_core.ReadNetwork(model, blob); LOGS_DEFAULT(INFO) << "Read network Done"; - } catch (const std::exception& exp) { - ORT_THROW(log_tag + "[OpenVINO-EP] Exception while Reading network: " + std::string(exp.what())); + } catch (const InferenceEngine::details::InferenceEngineException& e) { + ORT_THROW(log_tag + "[OpenVINO-EP] Exception while Reading network: " + std::string(e.what())); } catch (...) { ORT_THROW(log_tag + "[OpenVINO-EP] Unknown exception while Reading network"); } From 442bb82ad7f2806199042732f6f7432b050e6e80 Mon Sep 17 00:00:00 2001 From: MaajidKhan Date: Thu, 14 Jan 2021 21:48:29 +0530 Subject: [PATCH 3/3] Fixes compilation issue with ov_2021.1 ->The UEP component fails to compile with OpenVINO_2021.1 release version due to indentation error.Indentation is fixed with this commit. Signed-off-by: MaajidKhan --- .../openvino/ov_versions/capability_2021_1.cc | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_versions/capability_2021_1.cc b/onnxruntime/core/providers/openvino/ov_versions/capability_2021_1.cc index d6459c4c3a79e..a31b4b4f9a062 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/capability_2021_1.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/capability_2021_1.cc @@ -272,16 +272,17 @@ static bool IsUnsupportedOpMode(const Node* node, const GraphViewer& graph_viewe return true; } } else if (optype == "Max" || optype == "Min" || optype == "Mean" || optype == "Sum") { - if (GetInputCount(node, initializers) == 1) + if (GetInputCount(node, initializers) == 1) { return true; - if (optype == "Max" || optype == "Min") { - for (size_t i = 0; i < node->InputDefs().size(); i++) { - auto dtype = node->InputDefs()[i]->TypeAsProto()->tensor_type().elem_type(); - if (dtype == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_UINT8 || - dtype == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_INT16) - return true; - } + } + if (optype == "Max" || optype == "Min") { + for (size_t i = 0; i < node->InputDefs().size(); i++) { + auto dtype = node->InputDefs()[i]->TypeAsProto()->tensor_type().elem_type(); + if (dtype == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_UINT8 || + dtype == ONNX_NAMESPACE::TensorProto_DataType::TensorProto_DataType_INT16) + return true; } + } } else if (optype == "Clip") { //Only float 16, float and double data types are supported const bool data_is_float = node->InputDefs()[0]->Type()->find("float") != std::string::npos;