老卫带你学---caffe问题汇总

在caffe编译过程中,不管是新的caffe,还是几年前的caffe,亦或是不同的配置,都会大大小小出现一些小问题,该文章尽量将所有遇到的问题全部汇总,方便后期查看。

##问题1:

Makefile:563: recipe for target '.build_release/src/caffe/test/test_smooth_L1_loss_layer.o' failed

打开这个文件删掉第11行报错的头文件
#include “caffe/vision_layers.hpp”

##问题2:

编译caffe出现错误:

make: *** [.build_release/src/caffe/common.o] Error 1

或者

Makefile:581: recipe for target '.build_debug/src/caffe/test/test_tanh_layer.o' failed

这是因为当前版本的caffe的cudnn实现与系统所安装的cudnn的版本不一致引起的。

解决办法:

1.将./include/caffe/util/cudnn.hpp 换成最新版的caffe里的cudnn的实现,即相应的cudnn.hpp.

  1. 将./include/caffe/layers里的,所有以cudnn开头的文件,例如cudnn_conv_layer.hpp。 都替换成最新版的caffe里的相应的同名文件。

3.将./src/caffe/layer里的,所有以cudnn开头的文件,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp,cudnn_sigmoid_layer.cu。

都替换成最新版的caffe里的相应的同名文件。(可以用已经正常安装好的新的caffe进行替换)

rbgirshick的py-faster-rcnn实现,因为其cudnn实现为旧版本的实现,所有出现了以上问题.

##问题3:

出现如下错误:

nvcc fatal   : Unsupported gpu architecture 'compute_20'

解决办法:由于安装的cuda版本是9.1,当前下载的caffe版本比较旧,需要修改里面的makefile文件,屏蔽makefile文件中CUDA_ARCH下面的部分代码,如图:
这里写图片描述

##问题4:

/usr/include/boost/python/detail/wrap_python.hpp:50:23: fatal error: pyconfig.h: No such file or directory

python路径都改为了anaconda的路径,但是CPLUS的path没有设置,系统中我也没把anaconda设置成默认的python导致的。

make clean 
export CPLUS_INCLUDE_PATH=/usr/include/python2.7 
make all -j8

##问题5:
在编译好faster-rcnn之后,需要将其数据与模型下载下来,可是当我们运行脚本时出现错误:

hades@hades-ThinkPad-Edge-E440:~/software/face-py-faster-rcnn-master/data/scripts$ ./fetch_faster_rcnn_models.sh 
File already exists. Checking md5...
Checksum is incorrect. Need to download again.
Downloading Faster R-CNN demo models (695M)...
--2018-08-09 17:23:12--  https://dl.dropboxusercontent.com/s/o6ii098bu51d139/faster_rcnn_models.tgz?dl=0
Resolving dl.dropboxusercontent.com (dl.dropboxusercontent.com)... 69.171.234.48
Connecting to dl.dropboxusercontent.com (dl.dropboxusercontent.com)|69.171.234.48|:443... failed: Connection refused.
Unzipping...

gzip: stdin: unexpected end of file
tar: Child returned status 1
tar: Error is not recoverable: exiting now
Done. Please run this command again to verify that checksum = ac116844f66aefe29587214272054668.

根本就下在不下来数据,于是有朋友将其数据存到百度云上,大家可以直接下载。
https://pan.baidu.com/s/1o8NdJrc

密码是:gbpo

##问题6:

在编译make pycaffe时出现错误:

rcnn$ make pycaffe
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:1:52: fatal error: Python.h: No such file or directory
 #include <Python.h>  // NOLINT(build/include_alpha)
                                                    ^
compilation terminated.
Makefile:507: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1
hades@hades-ThinkPad-Edge-E440:~/software/face

遇到此类问题基本是caffe找不到python,因此在make py之前反复确认下anaconda或python所在目录是否存在。

因为是从别人的github上download下来的faster-rcnn,所以在makefile.config文件中要修改自己的python路径。

这里写图片描述

##问题7:

在make pycaffe时遇到了很多的问题。

提示如下错误:

from caffe.proto import caffe_pb2
  File "/home/wenyangming/caffe_new/caffe/python/caffe/proto/caffe_pb2.py", line 10, in <module>
    from google.protobuf import symbol_database as _symbol_database

这是与protobuf相关的文件,应该是protobuf中缺少symbol_database.py这个文件,那就去github上下载吧。
https://github.com/google/protobuf

在prtobuf/python/google/protobuf中找到symbol_database.py文件拷贝到你的protobuf,

我的protobuf地址是 /usr/local/lib/python2.7/dist-packages/google/protobuf
问题成功解决。

再次输入import caffe时,又出现了如下错误:

_DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: 'module' object has no attribute 'Default'

##问题8:

make pycaffe成功之后,在python交互界面输入import caffe时出现:

caffe_pb2.py TypeError: __init__() got an unexpected keyword argument 'syntax'  #或者这一类的错误

你会看到提示caffe_pb2.py那些各种xx有点像乱码的错误,其实是编码格式的问题。

This is caused by difference of arguments of FileDescriptor (and other Desctiptors)

主要是protobuf版本的问题。caffe只支持的到2.×版本

####首先查看版本

protobuf --vertion

如果是3.×,卸载

sudo pip uninstall protobuf

再次查看版本

protobuf --version

如果还是显示的老版本号,手动在/usr/local/lib还有/usr/lib下删除protoc文件。

####下载老版本
https://github.com/google/protobuf/releases/tag/v2.6.1

tar -zxvf protobuf-2.6.1.tar.gz # 解压
 
sudo apt-get install build-essential # 不装会报错
 
cd protobuf-2.6.1/ # 进入目录
 
./configure # 配置安装文件
 
make -j8# 编译
 
make check -j8 # 检测编译安装的环境
 
sudo make install -j8# 安装

####检查是否安装成功

protoc --version

若成功则显示:

libprotoc 2.6.1

可能会出现错误或者还是显示的老版本号,错误原因:protobuf的默认安装路径是/usr/local/lib,而/usr/local/lib不在ubuntu体系默认的LD_LIBRARY_PATH里,所以就找不到lib

解决办法:
1.打开~/.profile # 打开配置文件在文件最后添加:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

2.保存退出,

source ~/.profile

3.然后,查看版本号

protoc --version

####重新编译caffe

make -j8
make pycaffe -j8

##问题9:

在caffe输入层用python时,出现下面的问题:

Traceback (most recent call last): 
File “./tools/train_net.py”, line 112, in 
max_iters=args.max_iters) 
File “/data1/user/fujikoli/train_proj/tools/../lib/fast_rcnn/train.py”, line 174, in train_net 
pretrained_model=pretrained_model) 
File “/data1/user/fujikoli/train_proj/tools/../lib/fast_rcnn/train.py”, line 43, in init 
self.solver = caffe.SGDSolver(solver_prototxt) 
File “/data1/user/fujikoli/train_proj/tools/../lib/roi_data_layer/layer.py”, line 91, in setup 
layer_params = yaml.load(self.param_str_) 
AttributeError: ‘RoIDataLayer’ object has no attribute ‘param_str_’

解决方法:
在最新的caffe版本中,param_str_换名了,叫param_str,把param_str_改为param_str即可。(我的当时居然是将param_str换成param_str_,所以大家根据自己的实际情况进行修改)

##问题10:

在运行demo.py脚本时,出现以下错误:

Check failed: error == cudaSuccess (2 vs. 0)  out of memory
*** Check failure stack trace: ***
Aborted (core dumped)

这是因为你得到的错误确实是内存不足,但它不是RAM,而是GPU内存(注意错误来自CUDA)。
通常,当caffe内存不足时 - 首先要做的是减少批量大小(以梯度精度为代价)或者改变图像和标签的尺寸

如果大家的GPU不够的话,强烈建议购买好的显卡!!!!
如果是测试脚本的话,大家可以这样运行脚本,加入参数–cpu

python tools/demo.py --cpu

这样的话,就可以运行成功。

这里写图片描述

##问题10:

在运行faster-rcnn中的demo.py时,虽然将其caffemodel修改为自己的model,但是在运行的时候出现如下错误:

Cannot copy param 0 weights from layer 'bbox_pred'; shape mismatch.  Source param shape is 12 4096 (49152); target param shape is 84 4096 (344064). To learn this layer's parameters from scratch rather than copying from a saved net, rename the layer.
*** Check failure stack trace: ***
Aborted (core dumped)

意思就是输出的类别数与模型不符,那么我们需要修改prototxt文件最后的类别为我们所需要的类别数。(路径为models/pascal_voc/VGG16/faster_rcnn_alt_opt/)
这里写图片描述
这里写图片描述

##问题11:
在运行faster-rcnn时出现以下错误:

AttributeError: 'module' object has no attribute 'text_format'

经过google之后发现是protobuf的本版发生了变换,之前在配置caffe的时候手动安装了protbuf,版本是2.5.0,后来安装了tensorflow 我回忆了一下,protobuf的版本貌似是发生了变换。

所以解决办法:sudo pip install protobuf==2.5.0

刚才又发现一个新的解决方法:

在文件./lib/fast_rcnn/train.py增加一行import google.protobuf.text_format 即可解决问题

问题12:

ubuntu下编译caffe出现.build_release/lib/libcaffe.so: undefined reference to google ::protobuf…的问题

请详看此文:
https://blog.csdn.net/e01528/article/details/79532462

问题13:

Traceback (most recent call last):
  File "/usr/lib/python2.7/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/usr/lib/python2.7/multiprocessing/process.py", line 114, in run
    self._target(*self._args, **self._kwargs)
  File "train_faster_rcnn_alt_opt.py", line 198, in train_fast_rcnn
    max_iters=max_iters)
  File "/home/lys/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 160, in train_net
    model_paths = sw.train_model(max_iters)
  File "/home/lys/py-faster-rcnn/tools/../lib/fast_rcnn/train.py", line 101, in train_model
    self.solver.step(1)
  File "/home/lys/py-faster-rcnn/tools/../lib/roi_data_layer/layer.py", line 144, in forward
    blobs = self._get_next_minibatch()
  File "/home/lys/py-faster-rcnn/tools/../lib/roi_data_layer/layer.py", line 63, in _get_next_minibatch
    return get_minibatch(minibatch_db, self._num_classes)
  File "/home/lys/py-faster-rcnn/tools/../lib/roi_data_layer/minibatch.py", line 55, in get_minibatch
    num_classes)
  File "/home/lys/py-faster-rcnn/tools/../lib/roi_data_layer/minibatch.py", line 100, in _sample_rois
    fg_inds, size=fg_rois_per_this_image, replace=False)
  File "mtrand.pyx", line 1176, in mtrand.RandomState.choice (numpy/random/mtrand/mtrand.c:18822)
TypeError: 'numpy.float64' object cannot be interpreted as an index

调整numpy版本

python -c "import numpy;print numpy.version.version"#查看numpy版本,1.12.1

sudo pip install -U numpy==1.11.0

问题14:

TypeError: 'numpy.float64' object cannot be interpreted as an index

出现这样的错误可以查看该文章 https://www.cnblogs.com/han1ning1/p/7858357.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值