Mac下安装caffe深度学习框架

经过两天的尝试与失败,终于成功在mac上成功编译caffe,总结过程可以分为依赖包的安装,以及caffe的编译过程,其中依赖包的安装过程中又涉及很多工具包,路径设置问题(大多数人的错误来自于此),所以当发现错误时,首先可以先看是否路径设置错误,在看是不是依赖包没安装完全,版本是否匹配,然后caffe编译的过程的错误大多来自Makefile.config的配置问题。成功编译,参考了两篇博客博客一博客二
首先安装caffe

git clone https://github.com/BVLC/caffe.git 
cd /usr/local/Cellar/caffe         (进入你caffe安装的目录)  
cp Makefile.config.example Makefile.config 

然后安装Anaconda,Anaconda可以看做Python的一个集成安装,安装它后就默认安装了python、IPython、集成开发环境Spyder和众多的包和模块。非常方便。

bash Anaconda2-4.2.0-MacOSX-x86_64.sh 

然后下载CUDA8.0,选择Mac OSX , 10.12, dmg(network)。
然后在terminal执行下面的命令:

brew update
brew tap homebrew/science
for x in snappy leveldb gflags glog szip hdf5 lmdb homebrew/science/opencv; do brew uninstall $x; brew install --fresh -vd $x; done
brew uninstall --force protobuf; brew install --with-python --fresh -vd protobuf
brew uninstall boost boost-python; brew install --fresh -vd boost boost-python
#we have to export this to make sure we include all the cuda and anaconda resources
export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/Cellar/anaconda2/lib:/usr/local/lib:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH
export CPLUS_INCLUDE_PATH=/usr/local/Cellar/anaconda2/include/python2.7/:

接下来就可以修改caffe/Makefile.config中的内容了。对比下列的内容修改(由于篇幅限制,只含有效程序)即可。没有出现的地方全部是被#所注释,只有下面内容有效。

  CPU_ONLY := 1
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_52,code=sm_52 \
        -gencode arch=compute_60,code=sm_60 \
        -gencode arch=compute_61,code=sm_61 \
        -gencode arch=compute_61,code=compute_61
BLAS := open
BLAS_INCLUDE := /usr/local/Cellar/openblas/0.2.18_2/include
BLAS_LIB := /usr/local/Cellar/openblas/0.2.18_2/lib
PYTHON_INCLUDE := /usr/include/python2.7 \
        /usr/lib/python2.7/dist-packages/numpy/core/include
 ANACONDA_HOME := /usr/local/Cellar/anaconda2
 PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
         $(ANACONDA_HOME)/include/python2.7 \
         $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include\
 PYTHON_LIB := $(ANACONDA_HOME)/lib
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

BUILD_DIR := build
DISTRIBUTE_DIR := distribute
TEST_GPUID := 0

然后执行

#using -j8 key to enable parallel building. Number after j is the number of the CPUs available, in my case it's 8
make all -j8
make test -j8

这里没错,然后执行

make runtest -j8

会出现如下错误:
.build_release/tools/caffe

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib

Referenced from: /Users/work/gitclone/caffe/.build_release/tools/caffe

Reason: image not found

make: * [runtest] Abort trap: 6
执行:

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/Cellar/anaconda2/lib:/usr/local/lib:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH

继续出错,然后执行:

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/usr/local/Cellar/anaconda2/lib:/usr/local/lib:/usr/lib
export CPLUS_INCLUDE_PATH=/usr/local/Cellar/anaconda2/include/python2.7/: 
install_name_tool -add_rpath '/usr/local/Cellar/anaconda2/lib'  /usr/local/Cellar/caffe/.build_release/tools/caffe

继续出错,如下:

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib
  Referenced from: /Users/work/gitclone/caffe/.build_release/test/test_all.testbin
  Reason: image not found
make: *** [runtest] Abort trap: 6

执行:

install_name_tool -add_rpath '/usr/local/Cellar/anaconda2/lib'  /usr/local/Cellar/caffe/.build_release/test/test_all.testbin
make runtest -j8

就成功了!!!
这里写图片描述
最后执行:

make pycaffe
#to run caffe we need to export path to the built caffe:
export PYTHONPATH=/usr/local/Cellar/caffe/python/:$PYTHONPATH
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值