Mac安装Caffe教程

来源:互联网 发布:解析域名打不开 编辑:程序博客网 时间:2024/05/01 02:39

1.根据官网教程安装Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2.Anaconda Python
从https://store.continuum.io/cshop/anaconda/下载和安装Anaconda Python包(其中包括Caffe框架用到的hdf5)
mac环境变量设置的方式有多种,采用的是 ~/.bash_profile
export PATH=~/anaconda/bin:$PATH

3.CUDA
从https://developer.nvidia.com/cuda-downloads下载并安装CUDA 7.0
## 不安装也ok 从http://www.nvidia.com/object/mac-driver-archive.html下载并安装最新的CUDA 独立驱动  ##
export PATH=/Developer/NVIDIA/CUDA-7.0/bin:$PATH
export DYLD_LIBRARY_PATH=/Developer/NVIDIA/CUDA-7.0/lib:$DYLD_LIBRARY_PATH

4.BLAS
brew install homebrew/science/openblas
需要在后面的Makefile.config中设置对应的 BLAS := open
5.cuDNN(用于GPU加速,如果没有GPU无需安装)
从https://developer.nvidia.com/cudnn页面下载并安装cuDNN库(别忘了在Makefile.config中取消USE_CUDNN := 1的注释)
由于安装的是CUDA7.0,所以cudnn6.5和cudnn7.0都可以
tar -xzvf cudnn-6.5-osx-v2.tgz
cd cudnn-6.5-osx-v2
sudo cp lib* /usr/local/cuda/lib
sudo cp cudnn.h /usr/local/cuda/include/
6.安装依赖项
brew tap homebrew/science
brew edit opencv
将下面两行
args << "-DPYTHON#{py_ver}_LIBRARY=#{py_lib}/libpython2.7.#{dylib}"
args << "-DPYTHON#{py_ver}_INCLUDE_DIR=#{py_prefix}/include/python2.7"
替换为
args << "-DPYTHON_LIBRARY=#{py_prefix}/lib/libpython2.7.dylib"
args << "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7"

brew install --fresh -vd snappy leveldb gflags glog szip lmdb homebrew/science/opencv
brew install --build-from-source --with-python --fresh -vd protobuf
brew install --build-from-source --fresh -vd boost boost-python
boost在后面编译时候存在问题,后续对应解决方案
7.配置环境变量

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:$HOME/anaconda/lib:/usr/local/lib:/usr/lib:

环境变量加入到了 ~/.bash_profile

8.编译安装caffe
下载
--------------------------------------------------
git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config
-------------------------------------------------

配置Makefile.config
-------------------------------------------------- 
USE_CUDNN := 1
#CPU_ONLY:=1 ##如果只用了CPU则反注释该项
BLAS := open
BLAS_INCLUDE := /usr/local/Cellar/openblas/0.2.14_1/include
BLAS_LIB := /usr/local/Cellar/openblas/0.2.14_1/lib

PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python2.7 \
$(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \ 

PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
--------------------------------------------------

中间可能会报错
http://playittodeath.ru/how-to-install-caffe-on-mac-os-x-yosemite-10-10-4/

functional_03(218): error: not a class or struct name
100 errors detected
make: *** [.build_release/cuda/src/caffe/layers/absval_layer.o] Error 1 
解决方案:
$ cd /usr/local
$ cd Library/Formula/
$ cp boost.rb boost_backup.rb
$ cp boost-python.rb boost-python_backup.rb
$ wget https://raw.githubusercontent.com/Homebrew/homebrew/6fd6a9b6b2f56139a44dd689d30b7168ac13effb/Library/Formula/boost.rb
$ mv boost.rb.1 boost.rb
$ wget https://raw.githubusercontent.com/Homebrew/homebrew/3141234b3473717e87f3958d4916fe0ada0baba9/Library/Formula/boost-python.rb
$ mv boost-python.rb.1 boost-python.rb
$ brew uninstall --force boost
$ brew install boost

编译
make clean
make all -j8
make test
make runtest
make pycaffe
make distribute

$ export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/Users/kupa/anaconda/lib:/usr/local/lib:/usr/lib:/usr/local/Cellar/hdf5/:/usr/local/Cellar/:$DYLD_FALLBACK_LIBRARY_PATH


References:
http://luoyetx.me/2015/04/little-caffe/
http://blog.csdn.net/surgewong/article/details/43708339
http://ylzhao.blogspot.hk/2015/04/mac-os-x-1010caffe.html
http://www.myexception.cn/operating-system/1934587.html
http://hoondy.com/2015/04/03/how-to-install-caffe-on-mac-os-x-10-10-for-dummies-like-me/
http://playittodeath.ru/how-to-install-caffe-on-mac-os-x-yosemite-10-10-4/
https://aisgit.informatik.uni-freiburg.de/zhang/caffe_future/blob/ais-master/docs/installation.md
https://haduonght.wordpress.com/2015/02/21/install-caffe-on-mac-os-x-10-10/

0 0
原创粉丝点击