|
|
|
@ -3157,6 +3157,8 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe |
|
|
|
|
{ |
|
|
|
|
CV_TRACE_FUNCTION(); |
|
|
|
|
|
|
|
|
|
CV_TRACE_REGION("register_inputs"); |
|
|
|
|
|
|
|
|
|
std::vector<String> inputsNames; |
|
|
|
|
std::vector<MatShape> inp_shapes; |
|
|
|
|
for (auto& it : ieNet.getInputsInfo()) |
|
|
|
@ -3175,6 +3177,8 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe |
|
|
|
|
cvNet.setInputShape(inputsNames[inp_id], inp_shapes[inp_id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CV_TRACE_REGION_NEXT("backendNode"); |
|
|
|
|
|
|
|
|
|
Ptr<BackendNode> backendNode; |
|
|
|
|
#ifdef HAVE_DNN_NGRAPH |
|
|
|
|
if (DNN_BACKEND_INFERENCE_ENGINE_NGRAPH == getInferenceEngineBackendTypeParam()) |
|
|
|
@ -3195,8 +3199,26 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe |
|
|
|
|
CV_Error(Error::StsNotImplemented, "This OpenCV version is built without Inference Engine NN Builder API support"); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CV_TRACE_REGION_NEXT("register_outputs"); |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_DNN_NGRAPH |
|
|
|
|
auto ngraphFunction = ieNet.getFunction(); |
|
|
|
|
#if INF_ENGINE_VER_MAJOR_LT(INF_ENGINE_RELEASE_2020_2) |
|
|
|
|
std::list< std::shared_ptr<ngraph::Node> > ngraphOperations; |
|
|
|
|
#else |
|
|
|
|
std::vector< std::shared_ptr<ngraph::Node> > ngraphOperations; |
|
|
|
|
#endif |
|
|
|
|
if (ngraphFunction) |
|
|
|
|
{ |
|
|
|
|
ngraphOperations = ngraphFunction->get_ops(); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
for (auto& it : ieNet.getOutputsInfo()) |
|
|
|
|
{ |
|
|
|
|
CV_TRACE_REGION("output"); |
|
|
|
|
|
|
|
|
|
LayerParams lp; |
|
|
|
|
int lid = cvNet.addLayer(it.first, "", lp); |
|
|
|
|
|
|
|
|
@ -3205,15 +3227,38 @@ 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_"; |
|
|
|
|
|
|
|
|
|
InferenceEngine::CNNLayerPtr ieLayer = ieNet.getLayerByName(it.first.c_str()); |
|
|
|
|
CV_Assert(ieLayer); |
|
|
|
|
if (ngraphFunction) |
|
|
|
|
{ |
|
|
|
|
CV_TRACE_REGION("ngraph_function"); |
|
|
|
|
bool found = false; |
|
|
|
|
for (const auto& op : ngraphOperations) |
|
|
|
|
{ |
|
|
|
|
CV_Assert(op); |
|
|
|
|
if (op->get_friendly_name() == outputName) |
|
|
|
|
{ |
|
|
|
|
const std::string typeName = op->get_type_info().name; |
|
|
|
|
cvLayer->type = typeName; |
|
|
|
|
found = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!found) |
|
|
|
|
CV_LOG_WARNING(NULL, "DNN/IE: Can't determine output layer type: '" << outputName << "'"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
CV_TRACE_REGION("legacy_cnn_layer"); |
|
|
|
|
InferenceEngine::CNNLayerPtr ieLayer = ieNet.getLayerByName(it.first.c_str()); |
|
|
|
|
CV_Assert(ieLayer); |
|
|
|
|
|
|
|
|
|
cvLayer->name = it.first; |
|
|
|
|
cvLayer->type = ieLayer->type; |
|
|
|
|
cvLayer->type = ieLayer->type; |
|
|
|
|
} |
|
|
|
|
ld.layerInstance = cvLayer; |
|
|
|
|
|
|
|
|
|
ld.backendNodes[DNN_BACKEND_INFERENCE_ENGINE_NGRAPH] = backendNode; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -3238,6 +3283,9 @@ Net Net::Impl::createNetworkFromModelOptimizer(InferenceEngine::CNNNetwork& ieNe |
|
|
|
|
for (int i = 0; i < inputsNames.size(); ++i) |
|
|
|
|
cvNet.connect(0, i, lid, i); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
CV_TRACE_REGION_NEXT("finalize"); |
|
|
|
|
|
|
|
|
|
cvNet.setPreferableBackend(getInferenceEngineBackendTypeParam()); |
|
|
|
|
|
|
|
|
|
cvNet.impl->skipInfEngineInit = true; |
|
|
|
|