From 658d9c3633b53e1e16bf3de312ef503ba1669abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Do=C5=82bniak?= Date: Fri, 28 Jan 2022 05:16:18 +0100 Subject: [PATCH] Removal of ONNX FE warning regarding Constant creation (#9935) --- .../onnx/frontend/src/core/graph.cpp | 7 +--- .../onnx/frontend/src/op/constant.cpp | 37 ++++++++----------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/frontends/onnx/frontend/src/core/graph.cpp b/src/frontends/onnx/frontend/src/core/graph.cpp index ed2f5483257..b043435b7da 100644 --- a/src/frontends/onnx/frontend/src/core/graph.cpp +++ b/src/frontends/onnx/frontend/src/core/graph.cpp @@ -75,12 +75,7 @@ Graph::Graph(const std::shared_ptr& model_proto, } catch (const error::invalid_external_data&) { // invalid external data makes initializers creation impossible throw; - } catch (const ngraph::ngraph_error& exc) { - NGRAPH_WARN << "\nCould not create an nGraph Constant for initializer '" << initializer_tensor.name() - << "'. Constant with a 0 value was created, make sure connected input is optional.\n" - << "Otherwise verify if the initializer contains a correct number of " - "elements matching the initializer's shape. \nDetailed error:\n" - << exc.what(); + } catch (const ngraph::ngraph_error&) { ng_constant = default_opset::Constant::create(tensor.get_ng_type(), Shape{}, {0}); } diff --git a/src/frontends/onnx/frontend/src/op/constant.cpp b/src/frontends/onnx/frontend/src/op/constant.cpp index 100d2c45403..e5993dfe0cb 100644 --- a/src/frontends/onnx/frontend/src/op/constant.cpp +++ b/src/frontends/onnx/frontend/src/op/constant.cpp @@ -19,18 +19,11 @@ namespace onnx_import { namespace op { namespace { template -inline std::shared_ptr __make_ng_constant(const element::Type& type, const Tensor& tensor) { +inline std::shared_ptr make_ng_constant_impl(const element::Type& type, const Tensor& tensor) { std::shared_ptr constant{nullptr}; try { constant = std::make_shared(type, tensor.get_shape(), tensor.get_data()); - } catch (const ngraph::ngraph_error& exc) { - NGRAPH_WARN << "\nCould not create an nGraph Constant for an ONNX Constant " - "node. " - << "Constant with a 0 value was created instead.\n" - << "Verify if the ONNX Constant node contains a correct number of " - "elements matching the node's shape. \n" - << "Detailed error:\n" - << exc.what(); + } catch (const ngraph::ngraph_error&) { constant = std::make_shared(type, Shape{}, 0); } @@ -44,67 +37,67 @@ inline std::shared_ptr make_ng_constant(const Tensor& t template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::f16, tensor); + return make_ng_constant_impl(element::f16, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::f32, tensor); + return make_ng_constant_impl(element::f32, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::f64, tensor); + return make_ng_constant_impl(element::f64, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::i8, tensor); + return make_ng_constant_impl(element::i8, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::i16, tensor); + return make_ng_constant_impl(element::i16, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::i32, tensor); + return make_ng_constant_impl(element::i32, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::i64, tensor); + return make_ng_constant_impl(element::i64, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::u8, tensor); + return make_ng_constant_impl(element::u8, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::u16, tensor); + return make_ng_constant_impl(element::u16, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::u32, tensor); + return make_ng_constant_impl(element::u32, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::u64, tensor); + return make_ng_constant_impl(element::u64, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::boolean, tensor); + return make_ng_constant_impl(element::boolean, tensor); } template <> inline std::shared_ptr make_ng_constant(const Tensor& tensor) { - return __make_ng_constant(element::bf16, tensor); + return make_ng_constant_impl(element::bf16, tensor); } inline std::shared_ptr make_constant(const Tensor& tensor) {