mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 05:29:54 +08:00
Merge pull request #17134 from alalek:dnn_ie_avoid_conversion_to_legacy
This commit is contained in:
commit
2df978b8e7
@ -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;
|
||||
|
@ -277,9 +277,18 @@ TEST_P(DNNTestOpenVINO, models)
|
||||
|
||||
const Backend backendId = get<0>(get<0>(GetParam()));
|
||||
const Target targetId = get<1>(get<0>(GetParam()));
|
||||
std::string modelName = get<1>(GetParam());
|
||||
|
||||
if (backendId != DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && backendId != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
|
||||
throw SkipTestException("No support for async forward");
|
||||
ASSERT_FALSE(backendId != DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && backendId != DNN_BACKEND_INFERENCE_ENGINE_NGRAPH) <<
|
||||
"Inference Engine backend is required";
|
||||
|
||||
#if INF_ENGINE_VER_MAJOR_GE(2020020000)
|
||||
if (targetId == DNN_TARGET_MYRIAD && backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
{
|
||||
if (modelName == "person-detection-retail-0013") // IRv10
|
||||
applyTestTag(CV_TEST_TAG_DNN_SKIP_IE_MYRIAD, CV_TEST_TAG_DNN_SKIP_IE_NN_BUILDER, CV_TEST_TAG_DNN_SKIP_IE_VERSION);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (backendId == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019)
|
||||
setInferenceEngineBackendType(CV_DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_API);
|
||||
@ -288,7 +297,6 @@ TEST_P(DNNTestOpenVINO, models)
|
||||
else
|
||||
FAIL() << "Unknown backendId";
|
||||
|
||||
std::string modelName = get<1>(GetParam());
|
||||
bool isFP16 = (targetId == DNN_TARGET_OPENCL_FP16 || targetId == DNN_TARGET_MYRIAD);
|
||||
|
||||
const std::map<std::string, OpenVINOModelTestCaseInfo>& models = getOpenVINOTestModels();
|
||||
|
Loading…
Reference in New Issue
Block a user