Caffe 實踐 在macOS (版本號10.11) 上安裝Caffe

安裝Caffe

主要是按照Caffe官方指南安裝的,但遇到各種各樣的問題。下面把我安裝時遇到的問題和教訓列出來,做個記錄。我安裝的cuda版本是7.5,BLAS使用的是openblas,CuDNN版本是5.1

遇到的坑

  1. 無法用brew install 安裝snappy和leveldb。後來發現是因爲我更新了MacOS的版本,homebrew原有的版本就失效了,原本brew update能夠更新到最新的版本,但那個也失效了,於是我只能卸載掉homebrew重新安裝它。結果就成功安裝snappy和leveldb了
  2. make all的時候遇到protobuf incompatible version 問題。這是因爲protobuf更新到3.0.0,與舊版本不兼容。一定要make clean,再make all
  3. make all 遇到/bin/sh: /usr/local/cuda/bin/nvcc: No such file or directory。檢查Makefile搜索nvcc,發現其使用的是$(CUDA_DIR)/bin/nvcc 來訪問nvcc,研究發現後是因爲我只安裝了cuda driver沒有安裝cuda toolkit (https://developer.nvidia.com/cuda-75-downloads-archive) 而nvcc是在cuda toolkit裏面的。
  4. BLAS我使用的是openblas (使用brew install homebrew/science/openblas安裝,安裝完最後會輸出include和lib的位置。修改Makefile.config。BLAS := open; BLAS_INCLUDE := $(shell brew --prefix openblas)/include; BLAS_LIB := $(shell brew --prefix openblas)/lib
  5. make all太慢,使用make all -j4用四個線程編譯加速
  6. make all 最後出現了link錯誤ld: -rpath can only be used when targeting Mac OS X 10.5 or later. clang: error: linker command failed with exit code 1 (use -v to see invocation)。意識到可能是因爲我的xcode的版本太老,正好MacOs有10.12的更新,就更新了。
  7. make all 在MacOS 10.12上No receipt for 'com.apple.pkg.CLTools_Executables' found at '/' 。發現是Makefile裏確定XCODE Client 版本的腳本不兼容了XCODE_CLT_VER := $(shell pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep 'version' | sed 's/[^0-9]*\([0-9]\).*/\1/') 只好暫時修改XCODE_CLT_GEQ_7 :=1;來避開這個錯誤。但編譯的時候發現10.12 deprecated掉了很多函數,而protobuf還沒有改過來,於是產生了許多警告信息。
  8. make all遇到了nvcc fatal : The version ('80000') of the host compiler ('Apple clang') is not supported,這個時候可能nvcc也沒有對應10.12的更新了。。。只好去https://developer.apple.com/download/more/ 裝上http://adcdownload.apple.com/Developer_Tools/Command_Line_Tools_OS_X_10.11_for_Xcode_7.3.1/Command_Line_Tools_OS_X_10.11_for_Xcode_7.3.1.dmg 嘗試替換回舊的版本。使用sudo xcode-select --switch /Library/Developer/CommandLineTools切換成舊的版本。用clang --version驗證是7.3.0版而不是8.0.0版。終於make all成功了!!!!!(把之前第7步對Makefile的更改改回來)
  9. make runtest 遇到了no CUDA-capable device is detected 問題
    E1001 19:56:13.588129 3489002432 common.cpp:113] Cannot create Cublas handle. Cublas won't be available.
    E1001 19:56:14.732020 3489002432 common.cpp:120] Cannot create Curand generator. Curand won't be available.
    F1001 19:56:14.732951 3489002432 test_gradient_based_solver.cpp:462] Check failed: error == cudaSuccess (38 vs. 0) no CUDA-capable device is detected

    搜索了一下,覺得可能是因爲cuda driver的版本不夠高,只有7.5.26。於是到http://www.nvidia.com/object/mac-driver-archive.html 更新到7.5.30後,問題解決

安裝CuDNN

// 從https://developer.nvidia.com/cudnn下載最新的CuDNN
cd install_dir
sudo cp include/cudnn.h /Developer/NVIDIA/CUDA-7.5/include/
sudo cp lib/libcudnn* /usr/local/cuda/lib/
// 修改Makefile.config USE_CUDNN := 1
make clean; make all; make test; make runtest;

安裝pycaffe

// 下載Anaconda Python,可能需要重啓一下電腦讓python路徑指向Anaconda
cd caffe
for req in $(cat python/requirements.txt); do pip install $req; done
// 修改Makefile.config文件
// ANACONDA_HOME := $(HOME)/anaconda
// PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ 
                $(ANACONDA_HOME)/include/python2.7 \ 
                $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include                 
// PYTHON_LIB := $(ANACONDA_HOME)/lib               
brew install boost-python
make clean; make all -j4; make pycaffe
export PYTHONPATH=~/caffe/python/:$PYTHONPATH

遇到的坑(未解決)

  1. import caffe的時候遇到以下的問題:
    anaconda/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
    warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
    Illegal instruction: 4
    懷疑是因爲MacOS升級成10.12後的不兼容的問題。只能先放棄python了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章