0.關於caffe(by@寒小陽)
caffe是深度學習在映像領域廣泛使用的架構,其model zoo有大量的預訓練好的模型提供使用。映像相關應用會大量使用到caffe。
牆裂建議大家使用linux系統,原因如下。 linux系統(大部分公司為CentOS或者Ubuntu),才是實際開發中用到的系統,提前熟悉一下命令列,對於實際應用和開發都很有必要。 相對於Windows而言,linux下的依賴包安裝非常簡單。 Windows下編譯經常會出現大量問題,且現在網上Windows下caffe出現問題的解決方案非常少。 大量的二次開發和擴充都只有linux版本。 1.說明
下面是安裝caffe的一些筆記,寫的不明白的,歡迎在社區發帖問,也方便更多的同學查看相同的問題^_^ 2.關於系統
這個說明是關於linux系統的,最好是centOS 7.0以上,或者ubuntu 14.04 以上
因為低版本的裝不上相容合適的boost,opencv等庫 3.安裝依賴的庫
要確認一下,所有的庫都裝上了,否則編譯出來可能不能使用。
其中protobuf是用來定義layers的,leveldb是訓練時儲存圖片資料的資料庫,opencv是影像處理庫,boost是通用C++庫,等等...
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev 4.安裝科學計算和python所需的部分庫
sudo apt-get install openblas-dev numpy scipy matplotlib lapack-dev freetype-dev libpng-dev openblas-dev 5.安裝其餘依賴
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev 6.安裝git,拉取源碼
apt-get install git
git clone https://github.com/BVLC/caffe.git 7.安裝python的pip和easy_install,方便安裝軟體包
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
python ez_setup.py --insecure
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py 8.安裝python依賴(路徑根據自己的目錄可能要調一下)
cd caffe/python
執行
for req in $(cat requirements.txt); do pip install $req; done
這步安裝也有點慢,別急,等會兒,先去幹點別的 ^_^ 9.編輯caffe所需的Makefile檔案
cd caffe
cp Makefile.config.example Makefile.config
vim Makefile.config
Makefile.config裡面有依賴庫的路徑,及各種編譯配置,如果是沒有GPU的情況下,可以參照我下面幫你改的設定檔內容:
## 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 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 := /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