OpenVINO之链接库教程
1. 程序编好后为什么会提示plugins.xml:1:0: File was not found
我们回顾下OpenVINO(最新版本2020.2)的使用过程:
- 新建
InferenceEngine::Core core
- 读取模型,由
xxx.bin
与xxx.xml
- 配置输入输出格式(似乎这里可以不做,一切继承模型的配置)
- 将模型依靠
InferenceEngine::Core::LoadNetwork()
载入到硬件上 - 建立推理请求
CreateInferRequest()
- 准备输入数据
- 推理
- 接住推理后的输出
如果查看一下第一步的源码就可以知道,InferenceEngine::Core::Core
这个东西实际上是需要输入参数const std::string & xmlConfigFile
的,如下图所示:
因此,如果我们没有规定这个xmlConfigFile
的参数,它就会默认读取在inference_engine.so
文件路径下的plugins.xml
,可以查看windows下的your_openvino_install_root\Intel\OpenVINO\omz_demos_build\intel64\Release
或者Linux下的your_openvino_install_root/openvino/inference_engine/lib/intel64
找到。
为了好奇,可以看下plugins.xml
这个里面到底有什么,这也跟下面的问题2有关:
<ie>
<plugins>
<plugin name="GNA" location="libGNAPlugin.so">
</plugin>
<plugin name="HETERO" location="libHeteroPlugin.so">
</plugin>
<plugin name="CPU" location="libMKLDNNPlugin.so">
</plugin>
<plugin name="MULTI" location="libMultiDevicePlugin.so">
</plugin>
<plugin name="GPU" location="libclDNNPlugin.so">
</plugin>
<plugin name="MYRIAD" location="libmyriadPlugin.so">
</plugin>
<plugin name="HDDL" location="libHDDLPlugin.so">
</plugin>
<plugin name="FPGA" location="libdliaPlugin.so">
</plugin>
</plugins>
</ie>
2. 我至少该链接哪些OpenVINO的库
编译教程提示,最基本的库,需要链接libinference_engine.so
与libinference_engine_legacy.so
,所以也需要拖家带口把它们依赖的libinference_engine_transformations.so
和libngraph.so
还有libtbb.so.2
带上,需要注意的是,依赖库的路径有些并不是在your_openvino_install_root/openvino/inference_engine/lib/intel64
下的,各位同学可以通过ldd libinference_engine.so
的方式找到准确的依赖库的位置。算了,我这里就把路径全部提出来吧:
- libinference_engine.so: root/openvino/inference_engine/lib/intel64
- libinference_engine_legacy.so: root/openvino/inference_engine/lib/intel64
- libinference_engine_transformations.so: root/openvino/inference_engine/lib/intel64
- libngraph.so: root/deployment_tools/ngraph/lib/
- libtbb.so.2: root/openvino/inference_engine/external/tbb/lib
然后,冷静下,Core Inference Engine Libraries后面还有Device-specific Plugin Libraries,这就是plugins.xml
规定的plugin需要的库。根据模型运行在目标设备的类型,设置需要的库。比如,我的目标设备是CPU,所以就需要root/openvino/inference_engine/lib/intel64
下的libMKLDNNPlugin.so
,因此需要将plugins.xml
修改为:
<ie>
<plugins>
<plugin name="CPU" location="libMKLDNNPlugin.so">
</plugin>
</plugins>
</ie>
3. 提示符号未定义
my_lib.so: undefined reference to `InferenceEngine::Core::LoadNetwork(InferenceEngine::CNNNetwork, std::string const&, std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > > const&)'
my_lib.so: undefined reference to `InferenceEngine::Data::getName() const'
my_lib.so: undefined reference to `InferenceEngine::Core::Core(std::string const&)'
my_lib.so: undefined reference to `InferenceEngine::details::InferenceEngineException::InferenceEngineException(std::string const&, int, std::string const&)'
my_lib.so: undefined reference to `InferenceEngine::Core::ReadNetwork(std::string const&, std::string const&) const'
莫慌,看看my_lib.so
里面链接了什么:
可以看出,只链接了libinference_engine_legacy.so
,缺了libinference_engine.so
,为啥?检查下CMakeLists.txt
吧,看看编译选项有没有add_definitions(-D _GLIBCXX_USE_CXX11_ABI=0)
什么的,链接OpenVINO需要c++11或c++14。