mac 下安裝caffe(二)


使用Anaconda Python

1.brew edit opencv

      args << "-DPYTHON_LIBRARY=#{py_lib}/libpython2.7.#{dylib}"
      args << "-DPYTHON_INCLUDE_DIR=#{py_prefix}/include/python2.7"

替換成
      args << "-DPYTHON_LIBRARY=/Users/work/anaconda/lib/libpython2.7.#{dylib}"
      args << "-DPYTHON_INCLUDE_DIR=/Users/work/anaconda/include/python2.7"

 

2.去掉ANACONDA_HOME的注釋並修改為安裝的路徑

 ANACONDA_HOME := /Users/work/anaconda
 PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
         $(ANACONDA_HOME)/include/python2.7 \
         $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

 

3.再次make

出錯:Warning! ***HDF5 library version mismatched error***

brew uninstall hdf5

出錯:

ld: library not found for -lhdf5_hl

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make: *** [.build_release/lib/libcaffe.so.1.0.0-rc5] Error 1

 

makefile中還需要修改PYTHON_LIB如下:

#PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib

 

出錯:make runtest

.build_release/tools/caffe

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib

  Referenced from: /Users/work/gitclone/caffe/.build_release/tools/caffe

  Reason: image not found

make: *** [runtest] Abort trap: 6

 

設置一下環境變量DYLD_FALLBACK_LIBRARY_PATH 

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/Users/work/anaconda/lib:/usr/local/lib:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH

依然出錯。。。

 

哎哎哎,,,參照 http://playittodeath.ru/how-to-install-caffe-on-mac-os-x-yosemite-10-10-4/ 重新卸載編譯吧,依然是這個錯誤

export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/cuda/lib:/Users/work/anaconda/lib:/usr/local/lib:/usr/lib

export CPLUS_INCLUDE_PATH=/Users/work/anaconda/include/python2.7/: 

 

正確的方法為將添加libhdf5_hl.10.dylib所在路徑添加到rpath

install_name_tool -add_rpath '/Users/work/anaconda/lib'  /Users/work/gitclone/caffe/.build_release/tools/caffe

 

test_all.testbin 繼續出錯-->

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib

  Referenced from: /Users/work/gitclone/caffe/.build_release/test/test_all.testbin

  Reason: image not found

make: *** [runtest] Abort trap: 6

再次添加rpath

install_name_tool -add_rpath '/Users/work/anaconda/lib'  /Users/work/gitclone/caffe/.build_release/test/test_all.testbin

#這句不用 install_name_tool -add_rpath '/Users/work/anaconda/lib' /Users/work/gitclone/caffe/.build_release/lib/libcaffe.so

 

終於make runtest成功

Library not loaded錯誤參考:https://github.com/BVLC/caffe/issues/2320 

install_name_tool 參考 http://www.jianshu.com/p/193ba07dadcf 

查看可執行文件的依賴情況: otool -L  /Users/work/gitclone/caffe/.build_release/test/test_all.testbin

 

4.make pycaffe 

 import caffe 出錯:

ImportError: No module named google.protobuf.internal

 

conda install protobuf 即可解決

 

5.其他錯誤

a. RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9

系統自帶python的numpy版本為1.8.0rc1舊版本

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python

 

使用pip install numpy --upgrade 升級到1.12.0版本即可

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM