From 717f19714d1e52d3c0bbe7cd0f74d671e933031d Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Thu, 29 Jul 2021 09:50:27 +0300 Subject: [PATCH] Do not throw an exception if we have 2 result op for one tensor --- .../cnn_network_ngraph_impl.cpp | 8 ++++---- .../cnn_network/cnn_ngraph_impl_tests.cpp | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp b/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp index ba73bcc8917437..c60c515edda59a 100644 --- a/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp +++ b/inference-engine/src/inference_engine/cnn_network_ngraph_impl.cpp @@ -88,12 +88,12 @@ void CNNNetworkNGraphImpl::createDataForResult(const ::ngraph::Output<::ngraph:: void CNNNetworkNGraphImpl::validateFunctionNames() const { // nGraph function parameters and pre-Results operations should have unique names - std::unordered_set unique_names; + std::unordered_map> unique_names; for (const auto& param : _ngraph_function->get_parameters()) { if (unique_names.count(param->get_friendly_name())) { IE_THROW() << "Function contains several inputs with one friendly name!"; } - unique_names.insert(param->get_friendly_name()); + unique_names.insert({param->get_friendly_name(), param}); } for (const auto& result : _ngraph_function->get_results()) { const auto& parent = result->get_input_node_shared_ptr(0); @@ -101,10 +101,10 @@ void CNNNetworkNGraphImpl::validateFunctionNames() const { if (parent->get_output_size() > 1) { name += "." + std::to_string(result->get_input_source_output(0).get_index()); } - if (unique_names.count(name) && !ngraph::op::is_parameter(parent)) { + if (unique_names.count(name) && !ngraph::op::is_parameter(parent) && parent != unique_names.at(name)) { IE_THROW() << "Function contains several inputs and outputs with one friendly name!"; } - unique_names.insert(name); + unique_names.insert({name, parent}); } } diff --git a/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp b/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp index f25b38037fe1ce..40f19415754915 100644 --- a/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp +++ b/inference-engine/tests/functional/inference_engine/cnn_network/cnn_ngraph_impl_tests.cpp @@ -56,6 +56,26 @@ TEST(CNNNGraphImplTests, TestReshapeWithSameShape) { ASSERT_NO_THROW(net.reshape({{"input", SizeVector({1, 4000})}})); } +TEST(CNNNGraphImplTests, TestTwoResultsFromOneTensor) { + std::shared_ptr ngraph; + { + ngraph::PartialShape shape({1, 3, 22, 22}); + ngraph::element::Type type(ngraph::element::Type_t::f32); + auto param = std::make_shared(type, shape); + auto relu = std::make_shared(param); + auto result1 = std::make_shared(relu); + auto result2 = std::make_shared(relu); + + ngraph::ParameterVector params = {param}; + ngraph::ResultVector results = {result1, result2}; + + ngraph = std::make_shared(results, params); + } + + InferenceEngine::CNNNetwork cnnNet(ngraph); + ASSERT_NO_THROW(auto convertedNet = std::make_shared(cnnNet)); +} + TEST(CNNNGraphImplTests, TestInvalidReshape) { std::shared_ptr f; {