caffe编译遇到的问题(持续更新)
错误:/sbin/ldconfig.real: /usr/local/cuda-8.0/lib64/libcudnn.so.5 不是符号连接
解决:
在sudo ldconfig时遇到
usr/local/cuda-8.0/lib64/libcudnn.so.5 不是符号连接的问题,解决办法也很简单,重新建立链接并删除原链接
首先找到usr/local/cuda-8.0/lib64/目录,搜索 libcudnn 然后发现
两个文件
libcudnn.so.5 和libcudnn.so.5.0.5 理论上只有一个libcudnn.so.5.0.5
终端执行
ln -sf /usr/local/cuda-8.0/lib64/libcudnn.so.5.0.5 /usr/local/cuda-8.0/lib64/libcudnn.so.5
再sudo ldconfig时就可以了,这时候会发现usr/local/cuda-8.0/lib64/目录下只有
libcudnn.so.5.0.5 文件了,libcudnn.so.5消失了。
1:错误:
.build_release/tools/caffe: error while loading shared libraries: libhdf5.so.10: cannot open shared object file: No such file or directory
解决:
echo "export LD_LIBRARY_PATH=/home/abc/anaconda2/lib:$LD_LIBRARY_PATH" >>~/.bashrc
2.错误:
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so:对‘TIFFOpen@LIBTIFF_4.0’未定义的引用
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so:对‘TIFFReadEncodedStrip@LIBTIFF_4.0’未定义的引用
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so:对‘TIFFSetField@LIBTIFF_4.0’未定义的引用
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so:对‘TIFFSetWarningHandler@LIBTIFF_4.0’未定义的引用
/usr/lib/x86_64-linux-gnu/libopencv_highgui.so:对‘TIFFSetErrorHandler@LIBTIFF_4.0’未定义的引用
collect2:错误:ld返回1
make:*** [.build_release/tools/extract_features.bin]错误1
解决:
这个可能是权限问题,采用以下指令:
sudo su;
make all ;
make test ;
make runtest ;
make pycaffe;
一切都能顺利解决
编译matlab是会遇到错误,由于matlab版本不同而支持的编译器版本不同,所以会出现问题。
Matlab2014a(2015a)的版本是支持版本4.7.x所以在使用matlab调用mex文件的时候,基本上都会报错,根据报错信息,考虑如下两步解决方案。
1.降级安装gcc/g++版本为4.7.x
(1).下载gcc/g++4.7.x
$ sudo apt-get install -y gcc-4.7
$ sudo apt-get install -y g++-4.7
(2).链接gcc/g++实现降级
$ cd /usr/bin
$ sudo rm gcc
$ sudo ln -s gcc-4.7 gcc
$ sudo rm g++
$ sudo ln -s g++-4.7 g++
3.验证版本
gcc -v
之后再进行编译
4.错误:
python/caffe/_caffe.cpp:1:52:致命错误:Python.h:没有那个文件或目录
编译中断。
make:*** [python/caffe/_caffe.so]错误1
解决:
执行:sudofind / -name 'Python.h'找到他的路径,
在Makefile.config的PYTHON_INCLUDE加上/home/abc/anaconda2/include/python2.7\(路径是自己的)
5.错误:import caffe时:ImportError:No module named skimage.io
解决办法:
可能是我们没有安装所谓的skimage.io模块,所以可以用以下的命令来安装:
pip install scikit-image
关掉终端,重新进入再编译
或者:sudo pip install scikit-image
importcaffe
Traceback(most recent call last):
File"<stdin>", line 1, in <module>
ImportError:No module named caffe
解决:
echo'export PATH="/home/abc/caffe-master/python:$PATH"' >>~/.bashrc
source~/.bashrc
关掉终端,重新进入再编译
7.错误:InvalidMEX-file'/home/abc/caffe-master/matlab/+caffe/private/caffe_.mexa64':libhdf5.so.10: cannot open
sharedobject file: No such file or directory
解决:
在linux下输入:
ldd /home/abc/caffe-master/matlab/+caffe/private/caffe_.mexa64
在matlab的命令窗口输入:
!ldd /home/abc/caffe-master/matlab/+caffe/private/caffe_.mexa64 /home/abc/caffe-master/matlab/+caffe/private/caffe_.mexa64
看看哪个文件没有找到依赖项。我的是
libhdf5.so.10他no found然后再看看在linux下他的默认链接是哪一个:
libhdf5.so.10=> /home/abc/anaconda2/lib/libhdf5.so.10
然后:
sudo cp /home/abc/anaconda2/lib/libhdf5.so.10 /usr/lib/x86_64-linux-gnu
再在matlab窗口下看他又没有找到,一般就可以了。
這個命令
strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBCXX
的結果是:
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_3.4.21
GLIBCXX_DEBUG_MESSAGE_LENGTH
8.错误:
Checkfailed: error == cudaSuccess (2 vs. 0) out of memory
***Check failure stack trace: ***
@ 0x7fcd92132daa (unknown)
解决:
一次性读入的图片太多了,所以就超出了显存。因此需要将train.prototxt中的文件train和test的batch_size调小一点。
9.错误:
在生成lmdb时:
E0502 00:10:19.496055 5957 io.cpp:80] Could not open or find file /home/abc/caffe-master/data/mushroom/test1/2__09.png 0
解决方案:
1.检查数据图像存放的路径是否填写正确
2.在txt文件里面,图像路径与图像标签是否用空格” “分隔,“\t”分隔会出现此类错误(caffe版本更新,改变了分隔符号)
10.错误:
安装ubuntu14.04之后做的第一件事就是更新源,于是从网上找到来网易的源,结果更新后出现如下错误:W: 无法下载 http://mirrors.163.com/ubuntu/dists/trusty-security/main/binary-i386/Packages Hash 校验和不符
W: 无法下载 http://mirrors.163.com/ubuntu/dists/trusty-security/universe/binary-i386/Packages Hash 校验和不符。。。。。。。。。。。。。。。。。。。。。
解决:
更新软件源
11.升级gcc
sudo ln -s /usr/bin/gcc-5 /usr/bin/gcc -f
sudo ln -s /usr/bin/gcc++c-5 /usr/bin/gcc -f
sudo ln -s /usr/bin/gcc++-5 /usr/bin/g++ -f
sudo ln -s /usr/bin/gcc-5* /usr/bin/gcc -f
gcc -v
sudo ln -s /usr/bin/g++-5* /usr/bin/g++ -f
12。问题:
Makefile:588: recipe for target ‘.build_release/cuda/src/caffe/layers/embed_layer.o’ failed
make: * [.build_release/cuda/src/caffe/layers/embed_layer.o] Error 1
/usr/include/string.h: In function ‘void* __mempcpy_inline(void*, const void*, size_t)’:
/usr/include/string.h:652:42: error: ‘memcpy’ was not declared in this scope
return (char *) memcpy (__dest, __src, __n) + __n;
这个问题疑似跟Ubuntu16.04的版本有关系,google到一个方法:在caffe的Makefile里面第409行(我的)
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
更改为
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
13. ubuntu16.04配置MATLAB2016amatest问题:
在修改makefile里面的CXXFLAGS(大约410行),添加CXXFLAGS += -std=C++11后,直接 make matcaffe 。最后编译成功。
14.问题:
刚开始我是直接在终端输入:
- export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/usr/local/cuda-8.0/lib64
- export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4:/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libfreetype.so.6
首先终端输入:
- sudo gedit ~/.bashrc
- export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/:/usr/local/cuda-8.0/lib64
- export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4:/usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4:/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libfreetype.so.6
15.import caffe时错误提示
解决方式:
16。MATLAB_DIR must be specified in Makefile.config to build matcaffe.
解决方法:打开caffe-master 文件夹下的Makefile.config文件,找到有MATLAB_DIR:所在行:# MATLAB_DIR := /usr/local/MATLAB/R2014a,将该行的注释去掉。完美解决!
17.问题
symbol lookup error: /home/caffe/anaconda/lib/libreadline.so.6: undefined symbol: PC – caffe安装错误解决办法:
先执行命令locate libreadline.so.6
然后会发现比如系统目录下:/lib/x86_64-Linux-gnu/libreadline.so.6
会有这个文件
然后cp /lib/x86_64-linux-gnu/libreadline.so.6 ~/anaconda/lib
完美解决!
:$ conda install libgcc安装后:$ strings /home/abc/anaconda3/bin/../lib/libstdc++.so.6 | grep GLIBCXX 结果:GLIBCXX_3.4.19GLIBCXX_3.4.20GLIBCXX_3.4.21解决!
19.问题:
在caffe的make run test时error while loading shared libraries: libcudnn.so.5: cannot open shared object file: No such file ordirectory
2. $ sudo echo "/usr/local/cuda-8.0/lib64" > /etc/ld.so.conf.d/cuda.conf 3. $ sudo ldconfig20.问题:>>> import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'caffe'
解决:export PYTHONPATH=/home/abc/caffe-master/python:$PYTHONPATH
21.“fatal error: hdf5.h: 没有那个文件或目录”解决方法
Step 1
在Makefile.config文件的第95行,添加/usr/include/hdf5/serial/ 到INCLUDE_DIRS。版本不同可能代码有差别。
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
Step 2
在Makefile文件的第173行,把 hdf5_hl 和hdf5修改为hdf5_serial_hl 和hdf5_serial,也就是把下面第一行代码改为第二行代码。
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
22. blob size exceeds INT_MAX:
hdf5过大问题
23.错误Makefile:572:recipe for target ‘.build_release/lib/libcaffe.so.1.0.0’ failed
Makefile:572:recipe for target ‘.build_release/lib/libcaffe.so.1.0.0’ failed
make: * [.build_release/lib/libcaffe.so.1.0.0] Error 1
Error in caffe.set_mode_cpu (line 5) caffe_('set_mode_cpu'); Error in caffe.run_tests (line 6) caffe.set_mode_cpu(); >> Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: com.mathworks.services.settings.SettingValidationException: IMsgIDException for "matlab.workingfolder.LastFolderPath": Internal Error: No write permission on directory /home/ubuntu/.matlab/R2017a/temp0x9290x2244. Details: fl:filesystem:AccessDenied. at com.mathworks.mlwidgets.prefs.InitialWorkingFolder.setStringSettingValue(InitialWorkingFolder.java:52) at com.mathworks.mlwidgets.prefs.InitialWorkingFolder.access$000(InitialWorkingFolder.java:15) at com.mathworks.mlwidgets.prefs.InitialWorkingFolder$1.actionPerformed(InitialWorkingFolder.java:34) Caused by: com.mathworks.services.settings.SettingValidationException: IMsgIDException for "matlab.workingfolder.LastFolderPath": Internal Error: No write permission on directory /home/ubuntu/.matlab/R2017a/temp0x9290x2244. Details: fl:filesystem:AccessDenied. at com.mathworks.services.settings.Setting.nativeSet(Native Method) at com.mathworks.services.settings.Setting.set(Setting.java:913) at com.mathworks.services.settings.Setting.set(Setting.java:769) at com.mathworks.services.settings.Setting.set(Setting.java:709) at com.mathworks.mlwidgets.prefs.InitialWorkingFolder.setStringSettingValue(InitialWorkingFolder.java:50) ... 24 more解决:切换到root用户再试一下。再有错参考问题14
25. 问题描述:
MEX-file '/home/zhangjiqing/caffe/matlab/+caffe/private/caffe_.mexa64' 无效:
/home/zhangjiqing/caffe/matlab/+caffe/private/caffe_.mexa64: undefined symbol:
_ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEER
解决:
make mattest 报出以上错误。
简单粗暴的解决方法就是将 usr/local/MATLAB/R2016b/bin/glnxa64 中 以下三个文件删除。(建议删除前进行备份)
服务器的内存不够。
29. ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
这是因为我装了tensorflow-gpu 1.5版本,而我用的是cuda 8.0和cudnn6.0,1.5版本要求cuda 9.0,我的做法就是滚回:
- pip install tensorflow-gpu==1.4