Install Prerequisite
- No need to install CUDA and Xcode if using CPU only mode.
- Install Anaconda before Homebrew.
- Use Homebrew to install all the dependency according to the Caffe instruction
Install Caffe
With the official tool ‘make’. ‘cmake’ is provided by community and I met some strange errors.
- Copy the
Makefile.config.example
toMakefile.config
. - Modify the
Makefile.config
as following:
- Uncomment
CPU_ONLY := 1
to use CPU only mode. - Uncomment
USE_OPENCV := 0
USE_LEVELDB := 0
andUSE_LMDB := 0
to install the minimum interfate for caffe. - Uncomment and add
-std=c++11
to compilerCUSTOM_CXX := g++ -std=c++11
to give C++11 support. - Change
BLAS := open
since we will use openblas according to the dependency we installed. - Comment the original
BLAS_LIB
andBLAS_INCLUD
then uncomment theBLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib
since we installed openblas by brw. - Comment the original
PYTHON_INCLUDE
and uncomment theANACONDA_HOME
and thePYTHON_INCLUDE
with anaconda. - Change
PYTHON_LIB
to the anaconda version. - Uncomment
USE_PKG_CONFIG := 1
.
- Run
make caffe -j 4
to make caffe kernal with 4 threads.
Runtest for Caffe
- It is very possible to meet the following error in
make runtest
:
.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
According to this page, the right way to deal with this is to 添加libhdf5_hl.10.dylib所在路径添加到rpath by running install_name_tool -add_rpath '/Users/work/anaconda/lib' /Users/work/gitclone/caffe/.build_release/test/test_all.testbin
.
Install PyCaffe (the python interface)
- I met the following error:
ld: library not found for -lboost_python
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [python/caffe/_caffe.so] Error 1
To deal with this, according to this page, the answer is:
- vim Makefile (Take care, edit Makefile, not Makefile.config).
- use vim command :?boost_python (there should only be 1 occurrence)
- changed PYTHON_LIBRARIES ?= boost_python python2.7 to PYTHON_LIBRARIES ?= boost_python27 python2.7
- ran the command sudo make pycaffe
Import Caffe in Python
- To import python, the last thing we need to do is adding caffe to python path. According to this page, we should add to
~/.bash_profile
withexport PYTHONPATH=path_to_caffe/python:$PYTHONPATH
(Take care! Many answers says to addpath_to_caffe/python/caffe
and that won’t work.)
Import opencv installed by Homebrew at python
- According to this page, the cv2.os file is stored in
/usr/local/lib/python2.7/site-packages/
and we need to add this address to PYTHONPATH.