diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 245a2c5c1d..f03fa20626 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -2196,9 +2196,22 @@ struct Net::Impl : public detail::NetImplBase continue; auto ieInpNode = inputNodes[i].dynamicCast(); - CV_Assert(oid < ieInpNode->node->get_output_size()); + const auto& ngraph_input_node = ieInpNode->node; + CV_LOG_DEBUG(NULL, "DNN/IE: bind output port " << lid << ":" << oid << " (" << ngraph_input_node->get_friendly_name() << ":" << ngraph_input_node->get_type_info().name << ")"); + + // Handle parameters from other subnets. Output port is not used in this case + if ((ngraph::op::is_parameter(ngraph_input_node) || ngraph::op::is_constant(ngraph_input_node)) && + ngraph_input_node->get_output_size() == 1) + { + inputNodes[i] = Ptr(new InfEngineNgraphNode(ngraph_input_node)); + continue; + } + CV_CheckLT((size_t)oid, ngraph_input_node->get_output_size(), ""); #if INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_4) - inputNodes[i] = Ptr(new InfEngineNgraphNode(ieInpNode->node)); + // FIXIT refactor ".initNgraph()" API to use Output + // WA: use Concat to emulate Identity operation with requested output port + auto oid_node = std::make_shared(ngraph::OutputVector {ngraph_input_node->output(oid)}, 0); + inputNodes[i] = Ptr(new InfEngineNgraphNode(oid_node)); #elif INF_ENGINE_VER_MAJOR_GT(INF_ENGINE_RELEASE_2020_3) inputNodes[i] = Ptr(new InfEngineNgraphNode(ieInpNode->node->get_output_as_single_output_node(oid))); #else diff --git a/modules/dnn/src/ie_ngraph.cpp b/modules/dnn/src/ie_ngraph.cpp index 6736590161..916f5e0a18 100644 --- a/modules/dnn/src/ie_ngraph.cpp +++ b/modules/dnn/src/ie_ngraph.cpp @@ -330,7 +330,7 @@ public: InfEngineNgraphNode::InfEngineNgraphNode(std::shared_ptr&& _node) : BackendNode(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH), node(std::move(_node)) {} -InfEngineNgraphNode::InfEngineNgraphNode(std::shared_ptr& _node) +InfEngineNgraphNode::InfEngineNgraphNode(const std::shared_ptr& _node) : BackendNode(DNN_BACKEND_INFERENCE_ENGINE_NGRAPH), node(_node) {} InfEngineNgraphNode::InfEngineNgraphNode(const std::vector >& nodes, diff --git a/modules/dnn/src/ie_ngraph.hpp b/modules/dnn/src/ie_ngraph.hpp index 617f1d4542..bb593833ff 100644 --- a/modules/dnn/src/ie_ngraph.hpp +++ b/modules/dnn/src/ie_ngraph.hpp @@ -102,7 +102,7 @@ public: std::vector& internals); InfEngineNgraphNode(std::shared_ptr&& _node); - InfEngineNgraphNode(std::shared_ptr& _node); + InfEngineNgraphNode(const std::shared_ptr& _node); void setName(const std::string& name);