安装blas
$ sudo apt-get install libatlas-base-dev安装pip
sudo apt-get install python-pip安装其他依赖库
$ sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev protobuf-compiler liblmdb-dev libgflags-dev libgoogle-glog-dev liblmdb-dev $ sudo apt-get install python-dev $ sudo apt-get install python-opencv安装python模块
$ sudo apt-get install python-numpy python-scipy python-matplotlib python-sklearn python-skimage python-h5py python-protobuf python-leveldb python-networkx python-nose python-pandas python-gflags cython ipython安装过程不多说,网上教程很多,我习惯于下载好opencv,然后建立在opencv的主目录建立一个build文件夹,终端cd到该文件夹直接
cmake .. make sudo make install三、下载配置caffe 从github上直接下载
$ git clone git://github.com/BVLC/caffe.git用终端cd到caffe目录下
cp Makefile.config.example Makefile.config更改Makefile.config 的部分内容:
去掉CPU_ONLY :=1的注释 注释掉CUDA有关的行: #CUDA_DIR := /usr/local/cuda #CUDA_DIR := /usr #CUDA_ARCH := .... #TEST_GPUID := 0 去掉WITH_PYTHON_LAYER := 1的注释改正后:
make all make test make runtest make pycaffe都make成功后cd caffe/python 文件夹。打开python解释器, 若import caffe成功, 则安装成功
三、安装py-faster-rcnn
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git安装cython
sudo pip install cythoncd到/py-faster-rcnn/lib 修改setup.py文件,注释掉GPU相关代码,如下:
#CUDA = locate_cuda() #self.set_executable('compiler_so', CUDA['nvcc']) # Extension('nms.gpu_nms', # ['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'], # library_dirs=[CUDA['lib64']], # libraries=['cudart'], # language='c++', # runtime_library_dirs=[CUDA['lib64']], # this syntax is specific to this build system # we're only going to use certain compiler args with nvcc and not with # gcc the implementation of this trick is in customize_compiler() below extra_compile_args={'gcc': ["-Wno-unused-function"], # 'nvcc': ['-arch=sm_35','--ptxas-options=-v','-c','--compiler-options',"'-fPIC'"]}, #include_dirs = [numpy_include, CUDA['include']] #),setup.py修改完成后,在lib目录下执行
make接下来要编译caffe(项目自带的caffe-fast-rcnn) 修改Makefile.config,和之前修改caffe一样
cp Makefile.config.example Makefile.config更改Makefile.config 的部分内容:
去掉CPU_ONLY :=1的注释 注释掉CUDA有关的行: #CUDA_DIR := /usr/local/cuda #CUDA_DIR := /usr #CUDA_ARCH := .... #TEST_GPUID := 0 去掉WITH_PYTHON_LAYER := 1的注释改正后:
make -j8 && make pycaffe至此安装完毕
还要修改/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py文件部分内容 1.注销
#from nms.gpu_nms import gpu_nms2.改参数
def nms(dets, thresh, force_cpu=True):四、运行demo.py cd到py-faster-rcnn文件夹,下载caffe训练集以及所需要的文件
./data/scripts/fetch_faster_rcnn_models.shcd到/py-faster-rcnn/tools,运行
./demo.py --cpu之后可以看见系统已经训练好的模型运行效果。 但是cpu还是比较慢的。且容易内存溢出。如果我们换成zf网络模型(默认为VGG16)需要
./demo.py --cpu --net zf