mac10.9 安装caffe CPU_Only 模式

来源:互联网 发布:怎样使用淘宝优惠券 编辑:程序博客网 时间:2024/06/06 01:26

安装环境:
imac10.9 + anaconda(python)

安装Xcode

环境可能已经安装了XCODE,如果安装可能提示已经安装。

# open the terminal and inputxcode-select --install# when install success, you can input againxcode-select --install# said "error: command line tools are already installed...", well done

Homebrew安装

Homebrew如果已经安装,就不需要下面步骤。

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Python安装,我使用的是Anaconda

  1. 从https://store.continuum.io/cshop/anaconda/下载和安装Anaconda Python包(其中包括Caffe框架用到的hdf5)
  2. export PATH=~/anaconda/bin:$PATH(将Anaconda的bin路径添加到PATH环境变量中)
  3. 安装python的依赖包
$ sudo pip install -r /Users/ericliu/caffe/python/requirements.txt

安装各个依赖包。

Boost

Modify Formula for fix boost 1.55

cd /usr/local
git checkout a252214 /usr/local/Library/Formula/boost.rb

brew install --build-from-source boost boost-pythonbrew install --with-python protobuffor x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew install $x; done

修改brew的formulae

for x in snappy leveldb protobuf gflags glog szip boost boost-python lmdb homebrew/science/opencv; do brew edit $x; done

加入下面内容.

 def install      # ADD THE FOLLOWING:      ENV.append "CXXFLAGS", "-stdlib=libstdc++"      ENV.append "CFLAGS", "-stdlib=libstdc++"      ENV.append "LDFLAGS", "-stdlib=libstdc++ -lstdc++"      # The following is necessary because libtool likes to strip LDFLAGS:      ENV["CXX"] = "/usr/bin/clang++ -stdlib=libstdc++"      ...

brew的formulae按照上面内容替换。

源码编译方式安装下面依赖包

$ for x in snappy leveldb gflags glog szip lmdb homebrew/science/opencv; do brew uninstall $x; brew install --build-from-source --fresh -vd $x; done

重新编译之前,卸载旧的安装包。

Boost.python
1.55formula修正.

brew edit boost-python
文件里加入下面内容:

  homepage "http://www.boost.org"-  url "https://downloads.sourceforge.net/project/boost/boost/1.56.0/boost_1_56_0.tar.bz2"-  sha1 "f94bb008900ed5ba1994a1072140590784b9b5df"+  url 'https://downloads.sourceforge.net/project/boost/boost/1.55.0/boost_1_55_0.tar.bz2'+  sha1 'cef9a0cc7084b1d639e06cd3bc34e4251524c840'+  revision 2   head "https://github.com/boostorg/boost.git"

Boost安装

$ brew uninstall protobuf; brew install --build-from-source --with-python --fresh -vd protobuf$ brew install --build-from-source --fresh -vd boost boost-python

编译caffe源码

从Github上面克隆Caffe的代码

$ git clone https://github.com/BVLC/caffe.git$ cd caffe$ cp Makefile.config.example Makefile.config$ vim akefile.config

Make之前,CPUONYL模式编译Caffe时,Makefile.config进行修改:
1. 文件里CPU_ONLY:=1的注释去掉。
2. 检查并设置Python路径.
3. MATLAB_DIR路径设置

修改后的文件如下:

# To customize your choice of compiler, uncomment and set the following.# N.B. the default for Linux is g++ and the default for OSX is clang++# CUSTOM_CXX := g++# CUDA directory contains bin/ and lib/ directories that we need.CUDA_DIR := /usr/local/cuda# On Ubuntu 14.04, if cuda tools are installed via# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:# CUDA_DIR := /usr# CUDA architecture setting: going with all of them.# For CUDA < 6.0, comment the *_50 lines for compatibility.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# BLAS choice:# atlas for ATLAS (default)# mkl for MKL# open for OpenBlasBLAS := atlas# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.# Leave commented to accept the defaults for your choice of BLAS# (which should work)!# BLAS_INCLUDE := /path/to/your/blas# BLAS_LIB := /path/to/your/blas# Homebrew puts openblas in a directory that is not on the standard search path# BLAS_INCLUDE := $(shell brew --prefix openblas)/include# BLAS_LIB := $(shell brew --prefix openblas)/lib# This is required only if you will compile the matlab interface.# MATLAB directory should contain the mex binary in /bin.# MATLAB_DIR := /usr/localMATLAB_DIR := /Applications/MATLAB_R2015a.app# NOTE: this is required only if you will compile the python interface.# We need to be able to find Python.h and numpy/arrayobject.h.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 \# Uncomment to use Python 3 (default is Python 2)# PYTHON_LIBRARIES := boost_python3 python3.5m# PYTHON_INCLUDE := /usr/include/python3.5m \-- INSERT --# MATLAB_DIR := /usr/localMATLAB_DIR := /Applications/MATLAB_R2015a.app# NOTE: this is required only if you will compile the python interface.# We need to be able to find Python.h and numpy/arrayobject.h.#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)/anacondaPYTHON_INCLUDE := $(ANACONDA_HOME)/include \                  $(ANACONDA_HOME)/include/python2.7 \                  $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \# Uncomment to use Python 3 (default is Python 2)# PYTHON_LIBRARIES := boost_python3 python3.5m# PYTHON_INCLUDE := /usr/include/python3.5m \#                 /usr/lib/python3.5/dist-packages/numpy/core/include# We need to be able to find libpythonX.X.so or .dylib.#PYTHON_LIB := /usr/libPYTHON_LIB := $(ANACONDA_HOME)/lib# Homebrew installs numpy in a non standard path (keg only)# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include# PYTHON_LIB += $(shell brew --prefix numpy)/lib# Uncomment to support layers written in Python (will link against Python libs)# WITH_PYTHON_LAYER := 1# Whatever else you find you need goes here.INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/includeLIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies# INCLUDE_DIRS += $(shell brew --prefix)/include# LIBRARY_DIRS += $(shell brew --prefix)/lib# Uncomment to use `pkg-config` to specify OpenCV library paths.# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)# USE_PKG_CONFIG := 1BUILD_DIR := buildDISTRIBUTE_DIR := distribute# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171# DEBUG := 1# The ID of the GPU that 'make runtest' will use to run unit tests.TEST_GPUID := 0# enable pretty build (comment to see full commands)Q ?= @

编译Caffe

$ make clean$ make all$ make test$ make runtest$ make pycaffe$ make distribute

所有的测试通过.

出现错误:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: .build_release/lib/libcaffe.a(cudnn.o) has no symbols

CMakeCache.txt 里添加下面一句:(USE_libstdcpp:BOOL=FALSE)

“leveldb::DB::Open(leveldb::Options const&, std::__1::basic_string

$  sudo brew uninstall leveldbUninstalling /usr/local/Cellar/leveldb/1.18... (24 files, 1.3M)$ sudo brew install --build-from-source --fresh -vd leveldb
0 0
原创粉丝点击