From b339bb780b6a8b3957a6a7d644ab91e2a9836589 Mon Sep 17 00:00:00 2001 From: Evgenya Stepyreva Date: Thu, 30 Sep 2021 15:39:32 +0300 Subject: [PATCH] Resolved unexpected -1s in IRs (#7709) --- .../src/transformations/serialize.cpp | 54 ++++++++++++++++++- .../src/base/layer_test_utils.cpp | 1 + 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/inference-engine/src/transformations/src/transformations/serialize.cpp b/inference-engine/src/transformations/src/transformations/serialize.cpp index a14e9aa1a966bb..b992d2f49786eb 100644 --- a/inference-engine/src/transformations/src/transformations/serialize.cpp +++ b/inference-engine/src/transformations/src/transformations/serialize.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "ngraph/ops.hpp" #include "ngraph/opsets/opset.hpp" #include "ngraph/opsets/opset1.hpp" @@ -718,7 +719,7 @@ bool resolve_dynamic_shapes(const ngraph::Function& f) { for (size_t id = 0; id < f_ops.size(); ++id) { auto & op = f_ops[id]; auto & clone_op = f_clone_ops[id]; - + enable_constant_folding(clone_op); // to be able to fold ShapeOfs if (auto op_subgraph = std::dynamic_pointer_cast(op)) { resolve_dynamic_shapes(*op_subgraph->get_function()); } @@ -767,6 +768,56 @@ bool resolve_dynamic_shapes(const ngraph::Function& f) { return true; } +void auto_pad_resolving(ov::Node* node) { + const std::set pad_agnostic_types = { + ov::op::PadType::SAME_LOWER, + ov::op::PadType::SAME_UPPER, + ov::op::PadType::VALID, + ov::op::PadType::AUTO, + }; + if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0)); + op->set_adding_above(CoordinateDiff(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0)); + op->set_adding_above(CoordinateDiff(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0)); + op->set_pads_end(CoordinateDiff(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0)); + op->set_pads_end(CoordinateDiff(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0)); + op->set_pads_end(CoordinateDiff(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(CoordinateDiff(op->get_pads_begin().size(), 0)); + op->set_adding_above(CoordinateDiff(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(Shape(op->get_pads_begin().size(), 0)); + op->set_pads_end(Shape(op->get_pads_end().size(), 0)); + } + } else if (auto op = as_type(node)) { + if (pad_agnostic_types.count(op->get_auto_pad())) { + op->set_pads_begin(Shape(op->get_pads_begin().size(), 0)); + op->set_adding_above(Shape(op->get_pads_end().size(), 0)); + } + } +} + void ngfunction_2_irv10(pugi::xml_node& netXml, const ngraph::Function& f, const std::map& custom_opsets, @@ -905,6 +956,7 @@ void ngfunction_2_irv10(pugi::xml_node& netXml, } // fill general attributes + auto_pad_resolving(node); // Backward compatibility: clear padding values for nodes with auto_pad XmlSerializer visitor(data, node_type_name, custom_opsets, constant_node_write_handler); NGRAPH_CHECK(node->visit_attributes(visitor), "Visitor API is not supported in ", node); rt_info::XmlSerializer{data}.serialize(node->get_rt_info()); diff --git a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp index e318a36f6befc3..3a526aa53b2564 100644 --- a/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp +++ b/inference-engine/tests/functional/shared_test_classes/src/base/layer_test_utils.cpp @@ -75,6 +75,7 @@ void LayerTestsCommon::Serialize() { ngraph::pass::Manager manager; manager.register_pass(out_xml_path, out_bin_path); manager.run_passes(function); + function->validate_nodes_and_infer_types(); auto result = getCore()->ReadNetwork(out_xml_path, out_bin_path);