caffe:mac10.12安裝caffe的步驟

前言:caffe官網中安裝caffe時涉及的東西比較多而雜亂,其實有些東西能夠忽略掉。html

步驟:python

mac10.12自己自帶了python2.7,能夠使用系統自帶的pythongit

1.安裝Homebrew,pip,virtualenv(用於建立基於不一樣python版本的虛擬python環境,隔離不一樣python項目依賴的python環境)github

在終端中輸入  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"ruby

pip ,virtualenv的安裝自行googleapp

2.安裝caffe須要用到的一些依賴庫,在終端中依次輸入下面幾行python2.7

brew install -vd snappy leveldb gflags glog szip lmdb
# need the homebrew science source for OpenCV and hdf5
brew tap homebrew/science
brew install hdf5 opencv

# with Python pycaffe needs dependencies built from sourcecurl

brew install --build-from-source --with-python -vd protobufui

brew install --build-from-source -vd boost boost-pythongoogle

 

3.安裝caffe須要的BLAS,caffe官網描述(以下)的是能夠選擇使用mac自帶的 Accelerate / vecLib Framework,也能夠選擇OpenBLAS和MKL。我沒整明白Accelerate / vecLib Framework,我選擇的是安裝 openblas

BLAS: already installed as the Accelerate / vecLib Framework. OpenBLAS and MKL are alternatives for faster CPU computation.

下載 openblas源碼並編譯安裝到/usr/local目錄:

tar xvf OpenBLAS-0.2.19.tar.gz

cd OpenBLAS-0.2.19

make

make PREFIX=/usr/local install

到這裏,caffe須要依賴的全部庫安裝完畢,開始安裝caffe

 

4.安裝caffe

4.1.建立虛擬的python環境:

在終端執行:

virtualenv --no-site-packages vpy2.7forcaffe -p /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

source vpy2.7forcaffe/bin/activate #進入python的虛擬環境vpy2.7forcaffe

 

4.2.拉取caffe的源碼

在終端執行如下幾行:

git clone https://github.com/BVLC/caffe

cd /path/to/caffe #caffe的下載地址

cp Makefile.config.example Makefile.config

 

4.3.安裝caffe中的python需求環境(進行基於caffe的python開發所須要的python庫)

在終端執行如下幾行:

cd /path/to/caffe/python

for req in $(cat requirements.txt); do pip install $req; done

 

4.4.修改Makefile.config文件

1. 將 CPU_ONLY := 1的註釋去掉,這樣Caffe就只能在CPU上運行了

2.更改BLAS的配置

# BLAS choice:

# atlas for ATLAS (default)

# mkl for MKL

# open for OpenBlas

BLAS := open

# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.

# Leave commented to accept the defaults for your choice of BLAS

# (which should work)!

BLAS_INCLUDE := /usr/local/include

BLAS_LIB := /usr/local/lib

 

而後在終端執行:

make all

make test

make runtest

 

 

caffe安裝成功的話,會顯示以下:

 

 

5.爲了使用caffe的python接口,須要安裝pycaffe

在執行make pycaffe前,修改MakeFile.config文件的相關配置,以下:

修改1:

PYTHON_INCLUDE變量:將前面建立的虛擬python環境vpy2.7forcaffe中對應的include路徑追加到PYTHON_INCLUDE

PYTHON_LIB變量:將前面建立的虛擬python環境vpy2.7forcaffe中對應的lib路徑追加到PYTHON_LIB

 

修改2:numpy庫的的inclubde路徑和lib路徑分別追加到PYTHON_INCLUDE和PYTHONE_LIB變量中:

 

而後在終端執行以下操做:

cd /Users/XXX/caffe #caffe的下載地址

make pycaffe

相關文章
相關標籤/搜索