Caffe on Mac (CPU Only) 安裝記錄

在 Mac 上配置 Caffe 大概花了半天多的時(shí)間羹蚣,時(shí)間主要是花在解決各種奇怪的 error 上面了摄职。在此記錄一下配置的過(guò)程和遇到的問(wèn)題几颜,希望今后能少走一些彎路脸候。

安裝過(guò)程

  1. 安裝 Cuda穷娱。雖說(shuō)打算無(wú)腦運(yùn)行绑蔫,但還是安上了。

  2. 安裝 Homebrew 工具泵额。

  3. Homebrew 安裝 Caffe 依賴配深,有些安裝速度比較慢,耐心啊嫁盲。

# general dependencies
$ brew install -vd snappy leveldb gflags glog szip lmdb
$ brew tap homebrew/science
$ brew install hdf5 opencv
# with Python pycaffe needs dependencies built from source
$ brew install --build-from-source --with-python -vd protobuf
$ brew install --build-from-source -vd boost boost-python
$ brew install homebrew/science/openblas
  1. 修改文件篓叶。可以使用命令:
$ brew edit openCV 

或者由路徑 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-science/opencv.rb 直接尋找文件羞秤。

替換:
args << "-DPYTHON#{py_ver}_LIBRARY=#{py_lib}/libpython2.7.#{dylib}"
args << "-DPYTHON#{py_ver}_INCLUDE_DIR=#{py_prefix}/include/python2.7"
為:
args << "-DPYTHON_LIBRARY=#{py_prefix}/lib/libpython2.7.dylib"
args << "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7"
  1. 下載 Caffe 源碼并生成配置文件缸托。
$ git clone https://github.com/bvlc/caffe.git
$ cd caffe
$ cp Makefile.config.example Makefile.config
  1. 修改文件 Makefile.config。主要修改的地方有:
    1. 去掉注釋符瘾蛋,設(shè)置為 CPU_ONLY 模式俐镐。
    2. 配置 BLAS。
    3. 設(shè)置 Anaconda 路徑哺哼。
    4. 在 mac OS Sierra 環(huán)境下設(shè)置禁止使用 LevelDB(不兼容)佩抹。
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
# USE_CUDNN := 1

# 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_LEVELDB := 0
# USE_LMDB := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
#   You should not set this flag if you will be reading LMDBs with any
#   possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1

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

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++

# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr

# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 lines for compatibility.
CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
        -gencode arch=compute_20,code=sm_21 \
        -gencode arch=compute_30,code=sm_30 \
        -gencode arch=compute_35,code=sm_35 \
        -gencode arch=compute_50,code=sm_50 \
        -gencode arch=compute_50,code=compute_50

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas

# Homebrew puts openblas in a directory that is not on the standard search path
BLAS_INCLUDE := $(shell brew --prefix openblas)/include
BLAS_LIB := $(shell brew --prefix openblas)/lib

# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app

# 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 := /usr/local/Cellar/pyenv/20160726/versions/anaconda2-4.1.0
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

# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/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
INCLUDE_DIRS += $(shell brew --prefix)/include
LIBRARY_DIRS += $(shell brew --prefix)/lib

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

# 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 ?= @
  1. 編譯、測(cè)試取董。
$ make all
$ make runtest

發(fā)現(xiàn)有很多 warning棍苹,但這些不會(huì)影響工作。

  1. 為了可以在 python 中引入模塊茵汰,需要編譯 pycaffe枢里。在之后 import 時(shí)可能出現(xiàn)錯(cuò)誤 "No module named google.protobuf.internal",因此先要安裝 protobuf经窖。
pip install protobuf

之后編譯 pycaffe坡垫。

make pycaffe
make distribute
  1. 在 ".bash_profile" 中設(shè)置環(huán)境變量 PYTHONPATH
export PYTHONPATH=/Users/Dennis/caffe/python:$PYTHONPATH
  1. 完成画侣。
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末冰悠,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子配乱,更是在濱河造成了極大的恐慌溉卓,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,997評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件搬泥,死亡現(xiàn)場(chǎng)離奇詭異桑寨,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)忿檩,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,603評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門(mén)尉尾,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人燥透,你說(shuō)我怎么就攤上這事沙咏”嫱迹” “怎么了?”我有些...
    開(kāi)封第一講書(shū)人閱讀 163,359評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵肢藐,是天一觀的道長(zhǎng)故河。 經(jīng)常有香客問(wèn)我,道長(zhǎng)吆豹,這世上最難降的妖魔是什么鱼的? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 58,309評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮痘煤,結(jié)果婚禮上凑阶,老公的妹妹穿的比我還像新娘。我一直安慰自己速勇,他們只是感情好晌砾,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,346評(píng)論 6 390
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著烦磁,像睡著了一般养匈。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上都伪,一...
    開(kāi)封第一講書(shū)人閱讀 51,258評(píng)論 1 300
  • 那天土砂,我揣著相機(jī)與錄音姑丑,去河邊找鬼霉颠。 笑死蚜点,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的先誉。 我是一名探鬼主播湿刽,決...
    沈念sama閱讀 40,122評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼褐耳!你這毒婦竟也來(lái)了诈闺?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 38,970評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤铃芦,失蹤者是張志新(化名)和其女友劉穎雅镊,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體刃滓,經(jīng)...
    沈念sama閱讀 45,403評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡仁烹,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,596評(píng)論 3 334
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了咧虎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片卓缰。...
    茶點(diǎn)故事閱讀 39,769評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出征唬,到底是詐尸還是另有隱情震叮,我是刑警寧澤,帶...
    沈念sama閱讀 35,464評(píng)論 5 344
  • 正文 年R本政府宣布鳍鸵,位于F島的核電站,受9級(jí)特大地震影響尉间,放射性物質(zhì)發(fā)生泄漏偿乖。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,075評(píng)論 3 327
  • 文/蒙蒙 一哲嘲、第九天 我趴在偏房一處隱蔽的房頂上張望贪薪。 院中可真熱鬧,春花似錦眠副、人聲如沸画切。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 31,705評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)霍弹。三九已至,卻和暖如春娃弓,著一層夾襖步出監(jiān)牢的瞬間典格,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,848評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工台丛, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留耍缴,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,831評(píng)論 2 370
  • 正文 我出身青樓挽霉,卻偏偏與公主長(zhǎng)得像防嗡,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子侠坎,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,678評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容