Caffe 编译错误记录
装了opencv 3之后,以前可以编译成功的的caffe总是出现错误,现记录下来,作为备份:
- 1、build_release/lib/libcaffe.so:对‘cv::imdecode(cv::_InputArray const&, int)’未定义的引用
对于各种cv出错:
解决方法:
修改Makefile:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial matio opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
下次编译之前要 make clean - 2、make: /usr/local/bin/mexext:命令未找到
sudo ln -s /usr/local/MATLAB/R2016b/bin/mexext /usr/local/bin
警告: 您使用的 gcc 版本为 ‘5.4.0’。不支持该版本的 gcc。MEX 当前支持的版本为 ‘4.9.x’。有关当前支持的编译器列表,请参阅: http://www.mathworks.com/support/compilers/current_release。
不管它。
- 3、m//home/yali/anaconda2/lib/libpng16.so.16:对‘inflateValidate@ZLIB_1.2.9’未定义的引用
sudo ln -s /home/yali/anaconda2/lib/libpng16.so.16 libpng16.so.16 (方法不行)
正确解决方法:
在 Makefile.config 中,加入下一句
LINKFLAGS := -Wl,-rpath,$(HOME)/anaconda/lib - 4、python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
解决方法:没装numpy的先安装
sudo apt-get install python-numpy
然后 sudo find / -name numpy,显示
/usr/local/lib/python2.7/dist-packages/numpy/core/include/numpy
/usr/share/numpy
/usr/include/python2.7/numpy
/usr/include/numpy
/usr/lib/python2.7/dist-packages/Cython/Includes/numpy\
然后对照 Makefile.config
将第二行加一个local
PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/includ - 5、ImportError: No module named caffe
解决方法1:
首先新建一个py文件,命名为_init_paths.py 里面写入如下代码:
import os.path as osp
import sys
def add_path(path):
if path not in sys.path:
sys.path.insert(0, path)
this_dir = osp.dirname(__file__)
#Add caffe to PYTHONPATH
caffe_path = osp.join(this_dir, '..', 'caffe', 'python') #注意路径:this_dir表示当前路径,‘..’返回上一层的caffe所在的路径,根据自己的caffe所在路径修改
add_path(caffe_path)
每次使用caffe的时候在 import caffe 前面加上 import _init_paths 即可:
import _init_paths # _init_paths.py 和当前命令放在同一路径下
import caffe
解决方法2:
caffe_root = '/home/mmt/Desktop/caffe/)'
import sys
sys.path.append("/home/mmt/Desktop/caffe/python")
sys.path.append("/home/mmt/Desktop/caffe/python/caffe")
import caffe
- 6、编译Fast -rcnn时的错误
./include/caffe/util/cudnn.hpp:124:41: error: too few arguments to function
‘cudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMode_t, cudnnNanPropagation_t, int, int, int, int, int, int)’
解决方法:
1.将./include/caffe/util/cudnn.hpp 换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.
2.将./src/caffe/layer里的,所有以cudnn开头的文件,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp,cudnn_sigmoid_layer.cu。
rbgirshick的py-faster-rcnn实现,因为其cudnn实现为旧版本的实现,所有出现了以上问题.
然后 make clean,再重新编译
src/caffe/layers/cudnn_softmax_layer.cpp:6:48:
fatal error: caffe/layers/cudnn_softmax_layer.hpp: No such file or directory
将新版本caffe中的 incliude里面的layer文件夹移过去
- 7、ImportError: libprotobuf.so.8: cannot open shared object file: No such file
解决方法:http://blog.csdn.net/yl33489/article/details/73605398
http://blog.csdn.net/hailong0715/article/details/52057873
说明你使用的protobuf要么是没有编译过,所以找不到对应的库文件,要么就是您编译之后的安装路径没有假如到配置中所以报错。
如果是第一种,请先下载protobuf-2.5.0,我已经上传到网盘http://pan.baidu.com/s/1pKAgqp1
如果是第二种情况:
则需要创建新文件:/etc/ld.so.conf.d/libprotobuf.conf ,然后在其中加入内容:/usr/local/lib
- 8、TypeError: slice indices must be integers or None or have an _index_ method
说是numpy版本的问题。
解决方法:
sudo pip install -U numpy==1.11.0
python -c "import numpy; print numpy.__version__"
- 9、ImportError: numpy.core.multiarray failed to import
重新 make fasterrcnn/lib
10、SystemError: NULL result without error in PyObject_Call
解决方法:
sudo apt-get install python-yaml
- 10、./include/caffe/util/cudnn.hpp:8:34: fatal error: caffe/proto/caffe.pb.h: No such file or director
解决方法:
sudo pip install protobuf --upgrade -i http://pypi.douban.com/simple
sudo pip install pillow --upgrade -i http://pypi.douban.com/simple
- 11、/lib/rpn/proposal_layer.py:175: RuntimeWarning: invalid value encountered in
训练到8060次发生错误
解决方法:
将
1)A possible solution could be to decrease the base learning rate in the solver.prototxt(只能延迟错误出现的时间)
As it is recommended here http://caffe.berkeleyvision.org/tutorial/solver.html
Just change the base_lr: 0.001 to 0.0001
2)修改/py-faster-rcnn/lib/datasets/pascal_voc.py第204-207行,修改结果如下:(不顶用)
x1 = float(bbox.find('xmin').text)
y1 = float(bbox.find('ymin').text)
x2 = float(bbox.find('xmax').text)
y2 = float(bbox.find('ymax').text)
3)修改config中的RNG_seed, 只能延缓出现错误的时间。
- 12、error Check failed: error == cudaSuccess(77 vs 0) an illegal memory access was encountered
这是我在进行test的时候遇到的,训练的时候没有出错
解决方法:
将
ROIPoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), 16>>>(numpy.__version__"
中的16该一下行了,修改如下:
ROIPoolBackward<Dtype><<<CAFFE_GET_BLOCKS(count), CAFFE_CUDA_NUM_THREADS>>>
- 13、libcudart.so.8.0: cannot open shared object file: No such file or directory
首先打开bashrc文件:gedit ~/.bashrc
在文件末尾加入环境变量,如64-bit:export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64"
保存文件退出,在终端保存加载设置:soucre ~/.bashrc
或者
sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
- 14、ImportError: No module named cv2
sudo apt-get install python-opencv
- 15、 MATLAB caffe 运行错误
- _ZN2cv8imencodeERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_11_InputArrayERSt6vectorIhSaIhEERKSB_IiSaIiEE.
-先把 /usr/lib/x86_64-linux-gnu 里面的链接删掉或者保存起来
sudo ln -s /usr/lib/x86_64-linux-gnu/libopencv_core.so.2.4.9 libopencv_core.so.2.4
sudo ln -s /usr/lib/x86_64-linux-gnu/libopencv_highgui.so.2.4.9 libopencv_highgui.so.2.4
sudo ln -s /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.2.4.9 libopencv_imgproc.so.2.4 - 16、 MATLAB caffe 运行错误
Invalid MEX-file ‘/home/yali/Desktop/YALI/faster_rcnn/external/caffe/matlab/+caffe/private/caffe_.mexa64’:
/usr/local/MATLAB/R2016b/bin/glnxa64/../../sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found (required by
/home/yali/Desktop/YALI/faster_rcnn/external/caffe/matlab/+caffe/private/caffe_.mexa64).
sudo ln -sf /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21 /usr/local/MATLAB/R2016b/sys/os/glnxa64/libstdc++.so.6