OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[ONNX] Fix delegate when protobuf use default value (#32960)
Maxim Vafin3b165a8e75c4
diff --git a/src/frontends/onnx/frontend/src/core/decoder_proto.cpp b/src/frontends/onnx/frontend/src/core/decoder_proto.cppindex 96c0aa53f8c..c71d5a3488a 100644--- a/src/frontends/onnx/frontend/src/core/decoder_proto.cpp+++ b/src/frontends/onnx/frontend/src/core/decoder_proto.cpp@@ -31,27 +31,18 @@ ov::Any DecoderProto::get_attribute(const std::string& name) const {}switch (attr.type()) {case AttributeProto_AttributeType::AttributeProto_AttributeType_FLOAT:- if (attr.has_f())- return attr.f();- else- throw std::runtime_error("Attribute doesn't have value");- break;+ // do not check attr.has_f() because f has default value 0.0+ return attr.f();case AttributeProto_AttributeType::AttributeProto_AttributeType_FLOATS:return std::vector<float>{attr.floats().begin(), attr.floats().end()};case AttributeProto_AttributeType::AttributeProto_AttributeType_INT:- if (attr.has_i())- return attr.i();- else- throw std::runtime_error("Attribute doesn't have value");- break;+ // do not check attr.has_i() because i has default value 0+ return attr.i();case AttributeProto_AttributeType::AttributeProto_AttributeType_INTS:return std::vector<int64_t>{attr.ints().begin(), attr.ints().end()};case AttributeProto_AttributeType::AttributeProto_AttributeType_STRING:- if (attr.has_s())- return attr.s();- else- throw std::runtime_error("Attribute doesn't have value");- break;+ // do not check attr.has_s() because s has default value ""+ return attr.s();case AttributeProto_AttributeType::AttributeProto_AttributeType_STRINGS:return std::vector<std::string>{attr.strings().begin(), attr.strings().end()};case AttributeProto_AttributeType::AttributeProto_AttributeType_GRAPH:@@ -59,7 +50,7 @@ ov::Any DecoderProto::get_attribute(const std::string& name) const {return static_cast<ov::frontend::onnx::GraphIterator::Ptr>(std::make_shared<GraphIteratorProto>(m_parent, &attr.g()));else- throw std::runtime_error("Attribute doesn't have value");+ throw std::runtime_error("Attribute \"" + name + "\" doesn't have g value");break;case AttributeProto_AttributeType::AttributeProto_AttributeType_TENSOR:return static_cast<ov::frontend::onnx::DecoderBase::Ptr>(diff --git a/src/frontends/onnx/tests/models/affine_beta0.prototxt b/src/frontends/onnx/tests/models/affine_beta0.prototxtnew file mode 100644index 00000000000..98ceb9c0f46--- /dev/null+++ b/src/frontends/onnx/tests/models/affine_beta0.prototxt@@ -0,0 +1,54 @@+ir_version: 3+producer_name: "OpenVINO ONNX Frontend"+graph {+ node {+ input: "x"+ output: "y"+ op_type: "Affine"+ attribute {+ name: "alpha"+ f: 0.5+ type: FLOAT+ }+ attribute {+ name: "beta"+ type: FLOAT+ }+ }+ name: "test_model"+ input {+ name: "x"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim {+ dim_value: 1+ }+ dim {+ dim_value: 3+ }+ }+ }+ }+ }+ output {+ name: "y"+ type {+ tensor_type {+ elem_type: 1+ shape {+ dim {+ dim_value: 1+ }+ dim {+ dim_value: 3+ }+ }+ }+ }+ }+}+opset_import {+ version: 1+}diff --git a/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp b/src/frontends/onnx/tests/onnx_import_deprecated.in.cppindex 776b3088f92..f2b6097cba3 100644--- a/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp+++ b/src/frontends/onnx/tests/onnx_import_deprecated.in.cpp@@ -41,6 +41,19 @@ OPENVINO_TEST(${BACKEND_NAME}, onnx_model_affine) {test_case.run();}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_affine_beta0) {+ auto model = convert_model("affine_beta0.onnx");++ // input/output shape (1, 3)+ auto input = ov::test::NDArray<float, 2>{{{0.f, 1.f, 2.f}}}.get_vector();+ auto expected_output = ov::test::NDArray<float, 2>{{{0.f, 0.5f, 1.f}}}.get_vector();++ auto test_case = ov::test::TestCase(model, s_device);+ test_case.add_input(Shape{1, 3}, input);+ test_case.add_expected_output(Shape{1, 3}, expected_output);+ test_case.run();+}+OPENVINO_TEST(${BACKEND_NAME}, onnx_model_crop) {auto model = convert_model("crop.onnx");