您的位置:首页 > Web前端

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

2017-03-03 16:04 471 查看
本文转自博主,地址如下,仅为学习收藏用,在此谢过博主


http://blog.csdn.net/zyb19931130/article/details/53842791


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

General dependencies

[python]
view plain
copy

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

[python]
view plain
copy

sudo apt-get install libatlas-base-dev  

or install OpenBLAS or MKL for better CPU performance.

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

[python]
view plain
copy

sudo apt-get install python-dev   

如果是ubuntu14.04 ,还需要安装如下依赖:

[python]
view plain
copy

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev  

安装图像包依赖OpenCV开源库:

(1)从github上下载安装脚本:https://github.com/jayrambhia/Install-OpenCV
(2)进行Ubuntu/2.4目录,对所有脚本增加可执行权限

[python]
view plain
copy

sudo chmod +x *.sh  

(3)安装依赖项

[python]
view plain
copy

sudo ./dependencies.sh  

(4)安装opencv 2.4.9

[python]
view plain
copy

sudo sh ./opencv2_4_10.sh  

从caffe项目主页把caffe项目clone下来:

[python]
view plain
copy

git clone --recursive https://github.com/BVLC/caffe.git  

然后:

[python]
view plain
copy

cd caffe  
cp Makefile.config.example Makefile.config  

由于是仅CPU安装,修改Makefile相关配置:

[plain]
view plain
copy

去掉注释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  

文件修改完成后,开始编译:

[python]
view plain
copy

make all   
make test  
make runtest  
make pycaffe  

若编译没有错误,则编译成功。完成后:

[python]
view plain
copy

$cd caffe/python  
$python  
>>>import caffe  

若没有错误则表示安装成功,否则make clean,重新编译。
第二部分:py-faster-rcnn的CPU安装

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

[python]
view plain
copy

git clone --recursive  https://github.com/rbgirshick/py-faster-rcnn.git  

安装cython和easydict:

[python]
view plain
copy

sudo pip install cython  
sudo pip install easydict   

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




[python]
view plain
copy

#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:到/py-faster-rcnn/caffe-fast-rcnn/目录下,修改Makefile.config文件(和第一部分中的修改一样)和CMakeLists.txt文件(OFF改成ON),修改如下

[python]
view plain
copy

caffe_option(CPU_ONLY  "Build Caffe without CUDA support" ON) # TODO: rename to USE_CUDA  

[plain]
view plain
copy

cd ~/py-faster-rcnn/caffe-fast-rcnn  
make -j8&& make pycaffe  

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

[plain]
view plain
copy

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:

[plain]
view plain
copy

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

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








内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ubuntu caffe faster-rcnn cpu