Specialized exception if ONNX model is unsupported (#7234)

* Add tests

* Add new error throw
This commit is contained in:
Jan Iwaszkiewicz 2021-08-27 10:05:51 +02:00 committed by GitHub
parent 81c8cd711b
commit a81164e1cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 7 deletions

View File

@ -254,8 +254,9 @@ CNNNetwork details::ReadNetwork(const std::string& modelPath,
auto ngFunc = FE->convert(inputModel); auto ngFunc = FE->convert(inputModel);
return CNNNetwork(ngFunc, exts); return CNNNetwork(ngFunc, exts);
} }
IE_THROW() << "Unknown model format! Cannot find reader for model format: " << fileExt IE_THROW(NetworkNotRead) << "Unable to read the model: " << modelPath
<< " and read the model: " << modelPath << ". Please check that reader library exists in your PATH."; << " Please check that model format: " << fileExt
<< " is supported and the model is correct.";
} }
CNNNetwork details::ReadNetwork(const std::string& model, CNNNetwork details::ReadNetwork(const std::string& model,
@ -288,8 +289,8 @@ CNNNetwork details::ReadNetwork(const std::string& model,
return CNNNetwork(ngFunc, exts); return CNNNetwork(ngFunc, exts);
} }
IE_THROW() << "Unknown model format! Cannot find reader for the model and read it. Please check that reader " IE_THROW(NetworkNotRead)
"library exists in your PATH."; << "Unable to read the model. Please check if the model format is supported and model is correct.";
} }
} // namespace InferenceEngine } // namespace InferenceEngine

View File

@ -47,7 +47,7 @@ TEST(ONNXReader_ModelSupported, scrambled_keys) {
TEST(ONNXReader_ModelUnsupported, no_graph_field) { TEST(ONNXReader_ModelUnsupported, no_graph_field) {
// this model contains only 2 fields (it doesn't contain a graph in particular) // 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")), EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/no_graph_field.onnx")),
InferenceEngine::Exception); InferenceEngine::NetworkNotRead);
} }
TEST(ONNXReader_ModelUnsupported, incorrect_onnx_field) { 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 // this test will have to be changed if the number of fields in onnx.proto
// (ModelProto message definition) ever reaches 31 or more // (ModelProto message definition) ever reaches 31 or more
EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/incorrect_onnx_field.onnx")), EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/incorrect_onnx_field.onnx")),
InferenceEngine::Exception); InferenceEngine::NetworkNotRead);
} }
TEST(ONNXReader_ModelUnsupported, unknown_wire_type) { TEST(ONNXReader_ModelUnsupported, unknown_wire_type) {
// in this model the graph key contains wire type 7 encoded in it - this value is incorrect // 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")), EXPECT_THROW(InferenceEngine::Core{}.ReadNetwork(model_path("unsupported/unknown_wire_type.onnx")),
InferenceEngine::Exception); InferenceEngine::NetworkNotRead);
} }