Mac OS 10.12安裝caffe的步驟記錄
阿新 • • 發佈:2018-12-04
準本工作:
1、安裝Xcode,MacOS下的編譯工作需要用到,如果沒有安裝,可以到AppStore裡進行安裝
2、Python 可以不用安裝,系統自帶了2.7版本的python
3、brew,這個是個智慧化的安裝工具,非常好用,如果沒有安裝可以用下面的方法來安裝
ruby -e "$(curl --insecure -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
在我電腦執行上述命令的時候遇到了無法連線github的的問題
==> Downloading and installing Homebrew...
fatal: unable to access 'https://github.com/Homebrew/brew/': Empty reply from server
Failed during: git fetch origin master:refs/remotes/origin/master --tags --force
解決方法:
sudo vi /etc/hosts
在檔案的末尾加入如下內容
192.30.253.113 github.com
安裝依賴包:
brew install -vd snappy leveldb gflags glog szip lmdb
# 官方指導下面這句需要,但實際上不需要,可以直接安裝後面的依賴包了
brew tap homebrew/science
brew install hdf5 opencv
brew install --build-from-source --with-python -vd protobuf
BLAS:Mac自帶BLAS,無需安裝。brew install --build-from-source -vd boost boost-python
編譯caffe
git clone https://github.com/BVLC/caffe
cd /Users/XXX/caffe #caffe的下載地址
cp Makefile.config.example Makefile.config
需要修改Makefile.config
:
1. 將 CPU_ONLY := 1的註釋去掉,這樣Caffe就只能在CPU上運行了
開始編譯
make all
make test
make runtest
我在編譯過程中遇到了opencv無法連結的問題,提示如下
Undefined symbols for architecture x86_64:
"cv::imread(cv::String const&, int)", referenced from:
caffe::WindowDataLayer<float>::InternalThreadEntry() in window_data_layer.o
caffe::WindowDataLayer<double>::InternalThreadEntry() in window_data_layer.o
caffe::ReadImageToCVMat(std::string const&, int, int, bool) in io.o
"cv::imdecode(cv::_InputArray const&, int)", referenced from:
caffe::DecodeDatumToCVMat(caffe::Datum const&, int, int, bool) in io.o
ld: symbol(s) not found for architecture x86_64
這個問題我到stackoverflow上查到了答案
cv::imread(cv::String const&, int)
依賴於 libopencv_imgcodecs.dylib
但是Makefile缺失這個依賴專案,在Makefile里加入對opencv_imgcodecs 等相關內容的依賴即可,具體如下
LIBRARIES += glog gflags protobuf leveldb snappy \
lmdb \
boost_system \
hdf5_hl hdf5 \
opencv_imgcodecs opencv_highgui opencv_imgproc opencv_core pthread
加入上述內容後執行make all即可成功編譯caffe
最後執行完畢make runtest
大功告成!