ubuntu14.04安装CPU版caffe以及py-faster-rcnn

本文详细介绍如何在Ubuntu14.04环境下安装Caffe及py-faster-rcnn,包括所需依赖库的安装步骤、Caffe的编译配置、py-faster-rcnn的编译修改等,适用于计算机视觉和深度学习领域的研究人员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文转自博主,地址如下,仅为学习收藏用,在此谢过博主

http://blog.youkuaiyun.com/zyb19931130/article/details/53842791


第一部分:ubuntu16.04+caffe安装。。。。。我的是ubuntu14.04,   64位,问题不大

General dependencies

  1. sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler  
  2. sudo apt-get install --no-install-recommends libboost-all-dev  

BLAS: install ATLAS by
  1. sudo apt-get install libatlas-base-dev  

or install OpenBLAS or MKL for better CPU performance.

要使用Python调用caffe, 还需要python-dev包依赖:

  1. sudo apt-get install python-dev   
如果是ubuntu14.04 ,还需要安装如下依赖:
  1. sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev  
安装图像包依赖OpenCV开源库:
(1)从github上下载安装脚本: https://github.com/jayrambhia/Install-OpenCV

(2)进行Ubuntu/2.4目录,对所有脚本增加可执行权限

  1. sudo chmod +x *.sh  

(3)安装依赖项

  1. sudo ./dependencies.sh  
(4)安装opencv 2.4.9
  1. sudo sh ./opencv2_4_10.sh  
从caffe项目主页把caffe项目clone下来:
  1. git clone --recursive https://github.com/BVLC/caffe.git  
然后:
  1. cd caffe  
  2. cp Makefile.config.example Makefile.config  
由于是仅CPU安装,修改Makefile相关配置:
  1. 去掉注释CPU_ONLY :=1  
  2. 注释掉CUDA有关的行:  
  3. #CUDA_DIR := /usr/local/cuda  
  4. #CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \  
  5. #        -gencode arch=compute_20,code=sm_21 \  
  6. #        -gencode arch=compute_30,code=sm_30 \  
  7. #        -gencode arch=compute_35,code=sm_35 \  
  8. #        -gencode arch=compute_50,code=sm_50 \  
  9. #        -gencode arch=compute_50,code=compute_50  
  10. 去掉注释WITH_PYTHON_LAYER := 1  
  11. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial  
  12. 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  
  13. #TEST_GPUID := 0  
文件修改完成后,开始编译:
  1. make all   
  2. make test  
  3. make runtest  
  4. make pycaffe  
若编译没有错误,则编译成功。完成后:
  1. $cd caffe/python  
  2. $python  
  3. >>>import caffe  
若没有错误则表示安装成功,否则make clean,重新编译。

第二部分:py-faster-rcnn的CPU安装

下载项目,里面包含的caffe--rcnn与第一部分的caffe并不相同。

  1. git clone --recursive  https://github.com/rbgirshick/py-faster-rcnn.git  
安装cython和easydict:
  1. sudo pip install cython  
  2. sudo pip install easydict   

编译cython:到/py-faster-rcnn/lib/目录下修改setup.py文件,然后make,修改如下:

  1. #CUDA = locate_cuda()  
  2. #self.set_executable('compiler_so', CUDA['nvcc'])  
  3.     #Extension('nms.gpu_nms',  
  4.         #['nms/nms_kernel.cu', 'nms/gpu_nms.pyx'],  
  5.         #library_dirs=[CUDA['lib64']],  
  6.         #libraries=['cudart'],  
  7.         #language='c++',  
  8.         #runtime_library_dirs=[CUDA['lib64']],  
  9.         # this syntax is specific to this build system  
  10.         # we're only going to use certain compiler args with nvcc and not with  
  11.         # gcc the implementation of this trick is in customize_compiler() below  
  12.         #extra_compile_args={'gcc': ["-Wno-unused-function"],  
  13.         #                    'nvcc': ['-arch=sm_35',  
  14.         #                             '--ptxas-options=-v',  
  15.         #                             '-c',  
  16.         #                             '--compiler-options',  
  17.         #                             "'-fPIC'"]},  
  18.         #include_dirs = [numpy_include, CUDA['include']]  
  19.     #),  
编译caffe:到/py-faster-rcnn/caffe-fast-rcnn/目录下,修改Makefile.config文件(和第一部分中的修改一样)和CMakeLists.txt文件(OFF改成ON),修改如下
  1. caffe_option(CPU_ONLY  "Build Caffe without CUDA support" ON) # TODO: rename to USE_CUDA  
  1. cd ~/py-faster-rcnn/caffe-fast-rcnn  
  2. make -j8&& make pycaffe  
测试demo:

首先下载训练好的数据集:

  1. cd ~/py-faster-rcnn  
  2. ./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:

  1. cd ~/py-faster-rcnn  
  2. ./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

(3)https://github.com/rbgirshick/py-faster-rcnn




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值