From a81164e1cbf683e0d1665adf56f08e439be01d0f Mon Sep 17 00:00:00 2001 From: Jan Iwaszkiewicz Date: Fri, 27 Aug 2021 10:05:51 +0200 Subject: [PATCH] Specialized exception if ONNX model is unsupported (#7234) * Add tests * Add new error throw --- .../src/inference_engine/src/ie_network_reader.cpp | 9 +++++---- .../inference_engine/onnx_reader/model_support_tests.cpp | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/inference-engine/src/inference_engine/src/ie_network_reader.cpp b/inference-engine/src/inference_engine/src/ie_network_reader.cpp index f8c15a4f00d..a624f099dd0 100644 --- a/inference-engine/src/inference_engine/src/ie_network_reader.cpp +++ b/inference-engine/src/inference_engine/src/ie_network_reader.cpp @@ -254,8 +254,9 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath, auto ngFunc = FE->convert(inputModel); return CNNNetwork(ngFunc, exts); } - 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."; + IE_THROW(NetworkNotRead) << "Unable to read the model: " << modelPath + << " Please check that model format: " << fileExt + << " is supported and the model is correct."; } CNNNetwork details::ReadNetwork(const std::string& model, @@ -288,8 +289,8 @@ CNNNetwork details::ReadNetwork(const std::string& model, 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."; + IE_THROW(NetworkNotRead) + << "Unable to read the model. Please check if the model format is supported and model is correct."; } } // namespace InferenceEngine diff --git a/inference-engine/tests/functional/inference_engine/onnx_reader/model_support_tests.cpp b/inference-engine/tests/functional/inference_engine/onnx_reader/model_support_tests.cpp index 0ed41ca973e..75454a88c3e 100644 --- a/inference-engine/tests/functional/inference_engine/onnx_reader/model_support_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/onnx_reader/model_support_tests.cpp @@ -47,7 +47,7 @@ TEST(ONNXReader_ModelSupported, scrambled_keys) { TEST(ONNXReader_ModelUnsupported, no_graph_field) { // this model contains only 2 fields (it doesn't contain a graph in particular) EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/no_graph_field.onnx")), - InferenceEngine::Exception); + InferenceEngine::NetworkNotRead); } TEST(ONNXReader_ModelUnsupported, incorrect_onnx_field) { @@ -55,11 +55,11 @@ TEST(ONNXReader_ModelUnsupported, incorrect_onnx_field) { // this test will have to be changed if the number of fields in onnx.proto // (ModelProto message definition) ever reaches 31 or more EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/incorrect_onnx_field.onnx")), - InferenceEngine::Exception); + InferenceEngine::NetworkNotRead); } TEST(ONNXReader_ModelUnsupported, unknown_wire_type) { // in this model the graph key contains wire type 7 encoded in it - this value is incorrect EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/unknown_wire_type.onnx")), - InferenceEngine::Exception); + InferenceEngine::NetworkNotRead); }