资源下载:
上github下载faster R-CNN,解压缩。
我下载的是zip文件,解压后文件夹caffe-fast-rcnn是空的,需要在点开faster R-CNN主页上的caffe-fast-rcnn @ 0dcd397文件,将其内容下载下来并解压到对应的位置。
安装:
准备环境:
准备caffe的环境:
faster RCNN是在caffe框架下开发的,所以需要先准备caffe的相关依赖,之一部分参考博客Ubuntu14.04通过make+cmake编译安装caffe 的依赖安装部分。
安装cython, easydict
sudo pip install cython
sudo pip install easydict
生成Cython模型
首先,如果你用了独立显卡,需要修改关于独立显卡计算能力的部分。去CUDA-GPUS确定你的显卡的CUDA计算能力。我的是GT750,为3.0.所以修改$FRCN_ROOT/lib中的setup.py中的-arch=sm_XX为-arch=sm_30。具体位置如下:
extra_compile_args={'gcc': ["-Wno-unused-function"],
'nvcc': ['-arch=sm_30',
'--ptxas-options=-v',
'-c',
'--compiler-options',
"'-fPIC'"]},
include_dirs = [numpy_include, CUDA['include']]
),
cd $FRCN_ROOT/lib
make
这里用$FRCN_ROOT代表faster RCNN的根目录路径
修改配置文件
进入
faster RCNN中的caffe-fast-rcnn目录,执行命令
sudo cp Makefile.config.example Makefile.config
得到Makefile.config,打开并做如下修改:
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
也就是把WITH_PYTHON_LAYER := 1的注释去掉。其它的修改按自己的配置来,如果是按照博客Ubuntu14.04通过make+cmake编译安装caffe 准备的环境则不用做任何其它修改了。
编译安装
在根目录下执行
make -j4 && make pycaffe
运行
下载模型:
cd $FRCN_ROOT
./data/scripts/fetch_faster_rcnn_models.sh
运行demo:
./tools/demo.py --net zf
其中–net参数作用是选择zf模型还是VGG模型。我的显卡由于显存2G只能跑zf模型.
问题总结:
错误一
gph@gph-pc:~/Desktop/py-faster-rcnn-master/lib$ make
python setup.py build_ext --inplace
Traceback (most recent call last):
File "setup.py", line 12, in <module>
from Cython.Distutils import build_ext
ImportError: No module named Cython.Distutils
make: *** [all] Error 1
解决:
安装cython,sudo pip install cython
错误二
./tools/demo.py
ImportError: No module named easydict
解决:
安装easydict,sudo pip install easydict
错误三
ImportError: libcudart.so.6.5: cannot open shared object file: No such file or directory
or
ImportError: libcudart.so.6.5: wrong ELF class: ELFCLASS32
解决:
找到机器中正确版本的libcudart.so.6.5(64位和32为有区别),执行命令:export LD_LIBRARY_PATH=/usr/local/cuda-6.5/targets/x86_64-linux/lib:$LD_LIBRARY_PATH
错误四
Check failed: registry.count(type) == 1 (0 vs. 1) Unknown layer type: Python
解决:
makefile.config 文件下WITH_PYTHON_LAYER := 1的注释没去掉
错误五:
Check failed: error == cudaSuccess (2 vs. 0) out of memory
解决:跑zf模型:–net zf
错误六:
Check failed: error == cudaSuccess (8 vs. 0) invalid device function
根据你的显卡CUDA计算能力修改$FRCN_ROOT/lib中的setup.py中的-arch=sm_XX为-arch=sm_你的值。
错误七:
Traceback (most recent call last):
File “/home/gph/Desktop/py-faster-rcnn-master/tools/../lib/rpn/proposal_layer.py”, line 10, in
import yaml
ImportError: No module named yaml
Traceback (most recent call last):
File “./tools/demo.py”, line 135, in
net = caffe.Net(prototxt, caffemodel, caffe.TEST)
SystemError: NULL result without error in PyObject_Call
sudo apt-get install python-yaml