macOS 10.12.6 brew 安装 caffe(CPU-only)
1、安装brew
/usr/bin/ruby -e "$(curl -fsSLhttps://raw.githubusercontent.com/Homebrew/install/master/install)"
2、安装各种依赖
brew install -vd snappy leveldb gflags glog szip lmdb
brew tap homebrew/science
brew install hdf5 opencv
# 需要 pycaffe 输入
brew install --build-from-source --with-python -vd protobuf
brew install --build-from-source -vd boost boost-python
# 不需要 pycaffe
brew install protobuf boost
3、下载caffe并编译
git clone https://github.com/BVLC/caffe.git
cd caffe
mkdir build
# 编辑CMakeLists.txt OFF改为 ON
caffe_option(CPU_ONLY "Build Caffe without CUDA support" ON)
# 输入
cmake ..
# 如果在Python中输入import caffe时遇到Segmentation fault: 11问题,这是Python的库连接错误造成的
# 编辑build/CMakeCache.txt将
//Path to a library.
PYTHON_LIBRARY:FILEPATH=/usr/lib/libpython2.7.dylib
# 改为
//Path to a library.
PYTHON_LIBRARY:FILEPATH=/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
# 开始编译
make all –j
make pycaffe -j
make test -j
make runtest –j
# 为了能在python中使用caffe还需要在~/.bash_profile中添加生成的Python包路径,在.bash_profile中添加一句
export PYTHONPATH="/Users/xxx/caffe/python:$PYTHONPATH"
# xxx换成caffe实际解压的路径
# 完成
上图: