编译python3版本的caffe遇到的问题
如下链接是编译caffe的时候一些错误与解决
https://www.jianshu.com/p/36badc9fbcc2
我遇到的问题是编译成功了,但是运行的时候报错。
undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE
配置文件中是默认调用py2.7的boost。假如你使用py3调用了py2.7的boost的话,就会出现这样的错误内容。
这个错误内容在编译的时候是看不出的,因为编译跟py没有关系,只有在你调用的时候才会出现这些问题。
可以lld caffe可以看到编译好的生成的库的boost和py2.7相关的,而我们是需要用py3.7
ldd caffe|grep boost
如下是正确的依赖关系。
libboost_system.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 (0x00007f5d04613000)
libboost_filesystem.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_filesystem.so.1.65.1 (0x00007f5d03b4a000)
libboost_python3-py36.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_python3-py36.so.1.65.1 (0x00007f5d03582000)
libboost_thread.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1 (0x00007f5cf501c000)
libboost_regex.so.1.65.1 => /usr/lib/x86_64-linux-gnu/libboost_regex.so.1.65.1 (0x00007f5cf4d14000)
所以如何修改呢?
在Makefile.config中,打开注释:
#Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python3 python3.6m
PYTHON_INCLUDE := /usr/include/python3.6m \
/usr/lib/python3.6/dist-packages/numpy/core/include
重新编译,又报错:
base) root@e63bg6nh2esaf-0:/nf/TL_DATA/caffe-0.17.0-TL-cuda11/caffe-TL-for-pytorch# make pycaffe
CXX/LD -o python/caffe/_caffe.so .build_release/src/caffe/layers/python_layer.o
python/caffe/_caffe.cpp:11:10: fatal error: numpy/arrayobject.h: No such file or directory
#include <numpy/arrayobject.h>
^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:547: recipe for target 'python/caffe/_caffe.so' failed
这个感觉是py3没有装numpy,于是:
sudo apt install python3-numpy
解决!
问题2
root@e63bg6nesaf-0:/data/caffe-TL-cuda11-py3# make -j4
PROTOC src/caffe/proto/caffe.proto
CXX src/caffe/layer.cpp
CXX src/caffe/tensor.cpp
CXX src/caffe/type.cpp
In file included from src/caffe/type.cpp:1:0:
./include/caffe/type.hpp:9:10: fatal error: caffe/proto/caffe.pb.h: No such file or directory
#include "caffe/proto/caffe.pb.h"
^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Makefile:622: recipe for target '.build_release/src/caffe/type.o' failed
make: *** [.build_release/src/caffe/type.o]
解决方案:
https://blog.csdn.net/xiongmingkang/article/details/83421856
mkdir include/caffe/proto
protoc ./src/caffe/proto/caffe.proto --cpp_out=.
mv ./src/caffe/proto/caffe.pb.h ./include/caffe/proto/
好记性不如烂键盘---点滴、积累、进步!