本文转自博主,地址如下,仅为学习收藏用,在此谢过博主
http://blog.youkuaiyun.com/zyb19931130/article/details/53842791
第一部分:ubuntu16.04+caffe安装。。。。。我的是ubuntu14.04, 64位,问题不大
General dependencies:
- sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
- sudo apt-get install --no-install-recommends libboost-all-dev
BLAS: install ATLAS by
- sudo apt-get install libatlas-base-dev
or install OpenBLAS or MKL for better CPU performance.
要使用Python调用caffe, 还需要python-dev包依赖:
- sudo apt-get install python-dev
- sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
(1)从github上下载安装脚本: https://github.com/jayrambhia/Install-OpenCV
(2)进行Ubuntu/2.4目录,对所有脚本增加可执行权限
- sudo chmod +x *.sh
(3)安装依赖项
- sudo ./dependencies.sh
- sudo sh ./opencv2_4_10.sh
- git clone --recursive https://github.com/BVLC/caffe.git
- cd caffe
- cp Makefile.config.example Makefile.config
- 去掉注释CPU_ONLY :=1
- 注释掉CUDA有关的行:
- #CUDA_DIR := /usr/local/cuda
- #CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
- # -gencode arch=compute_20,code=sm_21 \
- # -gencode arch=compute_30,code=sm_30 \
- # -gencode arch=compute_35,code=sm_35 \
- # -gencode arch=compute_50,code=sm_50 \
- # -gencode arch=compute_50,code=compute_50
- 去掉注释WITH_PYTHON_LAYER := 1
- INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
- LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/i386-linux-gnu/hdf5/serial /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
- #TEST_GPUID := 0
- make all
- make test
- make runtest
- make pycaffe
- $cd caffe/python
- $python
- >>>import caffe
第二部分:py-faster-rcnn的CPU安装
下载项目,里面包含的caffe--rcnn与第一部分的caffe并不相同。
- git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
- sudo pip install cython
- sudo pip install easydict
编译cython:到/py-faster-rcnn/lib/目录下修改setup.py文件,然后make,修改如下:
- #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']]
- #),
- caffe_option(CPU_ONLY "Build Caffe without CUDA support" ON) # TODO: rename to USE_CUDA
- cd ~/py-faster-rcnn/caffe-fast-rcnn
- make -j8&& make pycaffe
首先下载训练好的数据集:
- cd ~/py-faster-rcnn
- ./data/scripts/fetch_faster_rcnn_models.sh
A:修改/py-faster-rcnn/lib/fast_rcnn/config.py文件(True改成False)
# Use GPU implementation of non-maximum suppression
__C.USE_GPU_NMS = False
B:将/py-faster-rcnn/tools/test_net.py和 /py-faster-rcnn/tools/train_net.py的caffe.set_mode_gpu()修改为caffe.set_mode_cpu().
C:修改/py-faster-rcnn/lib/fast_rcnn/nms_wrapper.py文件(注释该引用,并将False改成True)
#from nms.gpu_nms import gpu_nms
def nms(dets, thresh, force_cpu=True):
最后,运行demo:
- cd ~/py-faster-rcnn
- ./tools/demo.py --cpu
此时可能出现报错,nms_cpu.........not found,好吧,打开nms文件夹,看看里面的那个.py文件名字是不是和刚刚nms_wrapper.py中的import 的名字一致,不一致的对应在nms_wrapper.py修改时一并修改了OK
参考:
(1)http://caffe.berkeleyvision.org/install_apt.html
(2)https://github.com/BVLC/caffe