message: dnn(ie): fix layers extraction
diff: @@ -3228,6 +3228,7 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe
  for (auto& it : ieNet.getOutputsInfo())
  {
  CV_TRACE_REGION("output");
  + const auto& outputName = it.first;
  LayerParams lp;
  int lid = cvNet.addLayer(it.first, "", lp);
  @@ -3237,37 +3238,60 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe
  #ifdef HAVE_DNN_NGRAPH
  if (DNN_BACKEND_INFERENCE_ENGINE_NGRAPH == getInferenceEngineBackendTypeParam())
  {
  - const auto& outputName = it.first;
  Ptr<Layer> cvLayer(new NgraphBackendLayer(ieNet));
  cvLayer->name = outputName;
  cvLayer->type = "_unknown_";
  + auto process_layer = [&](const std::string& name) -> bool
  + {
  if (ngraphFunction)
  {
  CV_TRACE_REGION("ngraph_function");
  - bool found = false;
  for (const auto& op : ngraphOperations)
  {
  CV_Assert(op);
  - if (op->get_friendly_name() == outputName)
  + if (op->get_friendly_name() == name)
  {
  const std::string typeName = op->get_type_info().name;
  cvLayer->type = typeName;
  - found = true;
  - break;
  + return true;
  }
  }
  - if (!found)
  - CV_LOG_WARNING(NULL, "DNN/IE: Can't determine output layer type: '" << outputName << "'");
  + return false;
  }
  else
  {
  CV_TRACE_REGION("legacy_cnn_layer");
  - InferenceEngine::CNNLayerPtr ieLayer = ieNet.getLayerByName(it.first.c_str());
  + try
  + {
  + InferenceEngine::CNNLayerPtr ieLayer = ieNet.getLayerByName(name.c_str());
  CV_Assert(ieLayer);
  cvLayer->type = ieLayer->type;
  + return true;
  }
  + catch (const std::exception& e)
  + {
  + CV_UNUSED(e);
  + CV_LOG_DEBUG(NULL, "IE layer extraction failure: '" << name << "' - " << e.what());
  + return false;
  + }
  + }
  + };
  +
  + bool found = process_layer(outputName);
  + if (!found)
  + {
  + auto pos = outputName.rfind('.'); // cut port number: ".0"
  + if (pos != std::string::npos)
  + {
  + std::string layerName = outputName.substr(0, pos);
  + found = process_layer(layerName);
  + }
  + }
  + if (!found)
  + CV_LOG_WARNING(NULL, "DNN/IE: Can't determine output layer type: '" << outputName << "'");
  +
  ld.layerInstance = cvLayer;
  ld.backendNodes[DNN_BACKEND_INFERENCE_ENGINE_NGRAPH] = backendNode;
  }
  @@ -3277,10 +3301,23 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe
  #ifdef HAVE_DNN_IE_NN_BUILDER_2019
  Ptr<Layer> cvLayer(new InfEngineBackendLayer(ieNet));
  - InferenceEngine::CNNLayerPtr ieLayer = ieNet.getLayerByName(it.first.c_str());
  + InferenceEngine::CNNLayerPtr ieLayer;
  + try
  + {
  + ieLayer = ieNet.getLayerByName(outputName.c_str());
  + }
  + catch (...)
  + {
  + auto pos = outputName.rfind('.'); // cut port number: ".0"
  + if (pos != std::string::npos)
  + {
  + std::string layerName = outputName.substr(0, pos);
  + ieLayer = ieNet.getLayerByName(layerName.c_str());
  + }
  + }
  CV_Assert(ieLayer);
  - cvLayer->name = it.first;
  + cvLayer->name = outputName;
  cvLayer->type = ieLayer->type;
  ld.layerInstance = cvLayer;
  