1. 程式人生 > >Mac OS Mojave(10.14)配置 caffe cpu-only

Mac OS Mojave(10.14)配置 caffe cpu-only

配置環境homebrew + Anaconda Python 3.7 version

安裝步驟

安裝依賴項

brew install -vd snappy leveldb gflags glog szip lmdb
brew install hdf5 opencv wget
brew install openblas

安裝[email protected] [email protected] --with-python 可能會出錯,boost-python3是boost1.68版本,[email protected]暫時不支援python3

安裝protobuf3.5.1

cd ~/Downloads
wget https://github.com/protocolbuffers/protobuf/archive/v3.5.1.zip
unzip protobuf-3.5.1.zip
cd protobuf-3.5.1
./autogen.sh
./configure
make
make install

配置caffe

cd ~
git clone https://github.com/BVLC/caffe.git
cd caffe
cp Makefile.config.example Makefile.config

修改Makefile.config檔案:

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

# uncomment to disable IO dependencies and corresponding data layers
USE_OPENCV := 0
USE_HDF5 := 1

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

BLAS := open
BLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib

ANACONDA_HOME := $(HOME)/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		$(ANACONDA_HOME)/include/python3.7m \
		$(ANACONDA_HOME)/lib/python3.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
PYTHON_LIBRARIES := boost_python37 python3.7m
# 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

# 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/include
LIBRARY_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
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_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 ?= @

編譯

cd ~/caffe
make all
make test
make runtest1
make pycaffe
在~/caffe/python/caffe目錄下生_caffe.so就好了

錯誤解決

  1. make runtest 如果出現錯誤dyld: Library not loaded: @rpath/libhdf5_hl.100.dylib,將新增libhdf5_hl.100.dylib所在路徑新增到rpath:
    install_name_tool -add_rpath '/Users/lxy/anaconda3/lib' /Users/lxy/caffe/build/tools/caffe
    繼續make runtest,報錯dyld: Library not loaded:@rpath/libhdf5_hl.100.dylib,再次新增rpath:
    install_name_tool -add_rpath '/Users/lxy/anaconda3/lib' /Users/lxy/caffe/build/test/test_all.testbin

    ↩︎