qq70191 发表于 2017-7-5 20:18:06

caffe之mac下环境搭建

  参考



http://www.iyunv.com/Linux/2016-09/135026.html
  1. 安装brew,也叫homebrew,mac下类似于ubuntu的apt-get功能



curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1
brew update
  2. 安装git包,包含gitk,(注:brew doctor可以用来诊断brew)



a. 安装git
brew install git
b. 安装OpenBlas
brew install homebrew/science/openblas
c. 安装Caffe的依赖库,在终端输入如下命令:
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



Info1:
Homebrew no longer needs to have ownership of /usr/local. If you wish you can
return /usr/local to its default ownership with:
sudo chown root:wheel /usr/local
  3. 解决retina屏下gitk模糊的问题



# sudo chmod a+w /System/Library/Frameworks/Tk.framework/Versions/Current/Resources/Wish.app/Contents/Info.plist
# vim /System/Library/Frameworks/Tk.framework/Versions/Current/Resources/Wish.app/Contents/Info.plist 

  添加



 <!-- support retina screen, xiaxing -->
  <key>NSHighResolutionCapable</key>
  <true/>
  生效



# touch /System/Library/Frameworks/Tk.framework/Versions/Current/Resources/Wish.app
  4. 安装Xcode,caffe编译依赖很多库,xcode可以提供,从官方AppStore安装即可。
  5. 下载caffe工程,配置编译环境



git clone https://github.com/BVLC/caffe
cd <..>/caffe
cp Makefile.config.example Makefile.config   // 拷贝生成我们使用的config文件
  6. 修改Makefile.config文件,以下是我修改的部分,仅供参考:



# 我的电脑不支持GPU编译,选择CPU ONLY的编译选项

# CPU-only switch (uncomment to build without GPU support).
CPU_ONLY := 1


# 我的OpenCV版本为2.X,所以注视掉此行

# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3


# 我的python环境是Anaconda,打开对应注释

# 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)/anaconda2
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 \
#               /usr/lib/python3.5/dist-packages/numpy/core/include

# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
  7. 编译



# make all
# make test
# make runtest
  8. 编译python wrapper



# make pycaffe
  Error记录



Error 1.<resolved, 从AppStore安装Xcode>
-------------------------------------------------------------------------------------------------------------------
0000095573:caffe xiaxing$ make all
ls: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/: No such file or directory
CXX src/caffe/blob.cpp
In file included from src/caffe/blob.cpp:7:
In file included from ./include/caffe/util/math_functions.hpp:11:
./include/caffe/util/mkl_alternate.hpp:14:10: fatal error: 'cblas.h' file not found
#include <cblas.h>
^
1 error generated.
make: *** [.build_release/src/caffe/blob.o] Error 1
0000095573:caffe xiaxing$



Error 2.<# make pycaffe出错>
0000095573:caffe xiaxing$ make pycaffe


CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp


python/caffe/_caffe.cpp:10:10: fatal error: 'numpy/arrayobject.h' file not found


#include <numpy/arrayobject.h>


1 error generated.


make: *** Error 1



Error 3.
.build_release/test/test_all.testbin 0 --gtest_shuffle --gtest_filter="-*GPU*"
dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib
Referenced from: /Users/xiaxing/Desktop/baidu/caffe/caffe/.build_release/test/test_all.testbin
Reason: image not found
make: *** Trace/BPT trap: 5

解决:
install_name_tool -add_rpath '/Users/work/anaconda/lib'/Users/work/gitclone/caffe/.build_release/tools/caffe




Error 4.test_all.testbin 继续出错-->
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
解决:
install_name_tool -add_rpath '/Users/work/anaconda/lib'/Users/work/gitclone/caffe/.build_release/test/test_all.testbin
页: [1]
查看完整版本: caffe之mac下环境搭建