Machine Learning_安装_caffe

来源:互联网 发布:安卓闪退修复软件下载 编辑:程序博客网 时间:2024/05/17 22:51

参考:
http://www.tuicool.com/articles/FjAnqin
http://www.bubuko.com/infodetail-847860.html

  • 安装opencv
    由于已经安装了anaconda,有了大量python工具包,故不需要安装hdf5,只需要安装opencv

    brew tap homebrew/sciencebrew install opencv
  • 安装Boost和Boost-python 为了之后python接口的编译

    brew install --build-from-source --with-python -vd protobufbrew install --build-from-source -vd boost boost-python
  • Python接口:从Github上把Caffe下载下来解压后用命令行进入其中的Python文件夹执行以下命令来安装Python的依赖:

    cd caffe/pythonfor req in $(cat requirements.txt); do pip install $req; done
  • 修改Makefile.config

    • 去掉后缀.example

      cp Makefile.config.example Makefile.config
    • 修改

      将 CPU_ONLY := 1 的注释去掉
    • 然后就是后面的Python路径,用Anaconda Python的话将下面的注释去掉:

      ANACONDA_HOME := $(HOME)/anacondaPYTHON_INCLUDE := $(ANACONDA_HOME)/include \        $(ANACONDA_HOME)/include/python3.6m \        $(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
  • make

    cd caffemake all

    遇到问题:

    fatal error: 'gflags/gflags.h' file not found#include <gflags/gflags.h>

    原因:以为anaconda都有 就没有执行brew install -vd snappy leveldb gflags glog szip lmdb
    重新执行一遍。。。

    brew install -vd snappy leveldb gflags glog szip lmdb

    又出现问题:

    fatal error: 'cblas.h' file not found#include <cblas.h>

    解决:

    brew install openblas

    再解决:
    Go to the Makefile.config and edit the following lines with the path where your openblas is located, in my case the version is 0.2.19_1
    Be sure to uncomment these lines:

    BLAS_INCLUDE := /usr/local/Cellar/openblas/0.2.19_1/includeBLAS_LIB := /usr/local/Cellar/openblas/0.2.19_1/lib

    再make:

    make all

    再出现问题:

    clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]ld: library not found for -lhdf5_hlclang: error: linker command failed with exit code 1 (use -v to see invocation)make: *** [.build_release/lib/libcaffe.so.1.0.0] Error 1

     猜测是hdf5的问题,一看果然没有安装,坑…..
    装上hdf5:

    brew install hdf5

    再make:

    cd caffemake all

    终于make好了!!!!!!

    再继续make:

    make testmake runtest

再出现问题:

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib  Referenced from: /Users/xyq/caffe/.build_release/tools/caffe  Reason: image not foundmake: *** [runtest] Abort trap: 6

解决:

install_name_tool -add_rpath '/Users/xyq/anaconda/lib' /Users/xyq/caffe/.build_release/lib/libcaffe.so

嗯..没用
继续:
添加libhdf5_hl.10.dylib所在路径添加到rpath:

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

问题:

dyld: Library not loaded: @rpath/libhdf5_hl.10.dylib  Referenced from: /Users/xyq/caffe/.build_release/test/test_all.testbin  Reason: image not foundmake: *** [runtest] Abort trap: 6

再次添加rpath:

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

再次:

make runtest

终于ok!!!!
运行完runtest之后看到了一路绿色pass那么它的CPP接口是可以用的但是Python不一定

再make:

make pycaffe

又出现问题:

Undefined symbols for architecture x86_64:  "_PyUnicode_FromStringAndSize", referenced from:      boost::python::str::str<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in _caffe-bff5c8.o      boost::python::detail::no_proxy_helper<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, boost::python::detail::final_vector_derived_policies<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, false>, boost::python::detail::container_element<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, unsigned long, boost::python::detail::final_vector_derived_policies<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, false> >, unsigned long>::base_get_item_(boost::python::back_reference<std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >&> const&, _object*) in _caffe-bff5c8.o      boost::python::detail::caller_arity<1u>::impl<boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >::next, boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, boost::mpl::vector2<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, boost::python::objects::iterator_range<boost::python::return_value_policy<boost::python::return_by_value, boost::python::default_call_policies>, std::__1::__wrap_iter<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*> >&> >::operator()(_object*, _object*) in _caffe-bff5c8.o  "boost::python::detail::init_module(PyModuleDef&, void (*)())", referenced from:      _PyInit__caffe in _caffe-bff5c8.old: symbol(s) not found for architecture x86_64clang: error: linker command failed with exit code 1 (use -v to see invocation)make: *** [python/caffe/_caffe.so] Error 1

用otool -L 来查看boost

brew info boostotool -L /usr/local/Cellar/boost/1.64.0_1/lib/libboost_system.dylibbrew info boost-pythonotool -L /usr/local/Cellar/boost-python/1.64.0/lib/libboost_python.dylib

还是没有用……..

将caffe/python路径放入你的PYTHONPATH中注意/path/to/caffe/python是你caffe的地址,注意更改。

export PYTHONPATH=/Users/xyq/caffe/python:$PYTHONPATH

再次修改makefile

# We need to be able to find Python.h and numpy/arrayobject.h.PYTHON_INCLUDE := /Users/xyq/anaconda/include/python3.6m \        /Users/xyq/anaconda/lib/python3.6/site-packages/numpy/core/include

可能还是要安装cuda

好累 这次安装作废……..下次再….装……TT

原创粉丝点击