From 333e51b2171f51f6a75b49958038b76c51afd67c Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Wed, 26 Jun 2019 06:41:01 +0000 Subject: [PATCH] dnn: configure plugin path for InferenceEngine --- modules/dnn/src/op_inf_engine.cpp | 52 +++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/modules/dnn/src/op_inf_engine.cpp b/modules/dnn/src/op_inf_engine.cpp index a242733..3f96a1d 100644 --- a/modules/dnn/src/op_inf_engine.cpp +++ b/modules/dnn/src/op_inf_engine.cpp @@ -409,6 +409,14 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::ICNNNetwork& net) enginePtr = dispatcher.getSuitablePlugin(targetDevice); sharedPlugins[targetDevice] = enginePtr; + std::vector candidates; + + std::string param_pluginPath = utils::getConfigurationParameterString("OPENCV_DNN_IE_EXTRA_PLUGIN_PATH", ""); + if (!param_pluginPath.empty()) + { + candidates.push_back(param_pluginPath); + } + if (targetDevice == InferenceEngine::TargetDevice::eCPU || targetDevice == InferenceEngine::TargetDevice::eFPGA) { @@ -422,24 +430,36 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::ICNNNetwork& net) { if (!haveFeature[i]) continue; - #ifdef _WIN32 - std::string libName = "cpu_extension" + suffixes[i] + ".dll"; - #elif defined(__APPLE__) - std::string libName = "libcpu_extension" + suffixes[i] + ".dylib"; - #else - std::string libName = "libcpu_extension" + suffixes[i] + ".so"; - #endif // _WIN32 - try - { - InferenceEngine::IExtensionPtr extension = - InferenceEngine::make_so_pointer(libName); - enginePtr->AddExtension(extension, 0); - break; - } - catch(...) {} +#ifdef _WIN32 + candidates.push_back("cpu_extension" + suffixes[i] + ".dll"); +#elif defined(__APPLE__) + candidates.push_back("libcpu_extension" + suffixes[i] + ".so"); // built as loadable module + candidates.push_back("libcpu_extension" + suffixes[i] + ".dylib"); // built as shared library +#else + candidates.push_back("libcpu_extension" + suffixes[i] + ".so"); +#endif // _WIN32 } - // Some of networks can work without a library of extra layers. } + bool found = false; + for (size_t i = 0; i != candidates.size(); ++i) + { + const std::string& libName = candidates[i]; + try + { + InferenceEngine::IExtensionPtr extension = + InferenceEngine::make_so_pointer(libName); + enginePtr->AddExtension(extension, 0); + CV_LOG_INFO(NULL, "DNN-IE: Loaded extension plugin: " << libName); + found = true; + break; + } + catch(...) {} + } + if (!found && !candidates.empty()) + { + CV_LOG_WARNING(NULL, "DNN-IE: Can't load extension plugin (extra layers for some networks). Specify path via OPENCV_DNN_IE_EXTRA_PLUGIN_PATH parameter"); + } + // Some of networks can work without a library of extra layers. } plugin = InferenceEngine::InferencePlugin(enginePtr); -- 2.7.4