美文网首页
在 Xcode 中调试和研究 Caffe

在 Xcode 中调试和研究 Caffe

作者: kakukeme | 来源:发表于2017-07-11 17:28 被阅读270次

    先记录,后面再整理;

    在 Xcode 中调试和研究 Caffe

    在 Xcode 中调试和研究 Caffe
    Debug and Explorer Caffe in Xcode
    http://coldmooon.github.io/2016/03/18/debug_and_learn_caffe/

    1、caffe 编译参考这里;

    Mac10.12+XCode编译caffe(含GPU加速)
    http://blog.csdn.net/hanlin_tan/article/details/53365480

    // 首先,打开终端,切换到源码根目录,执行
    $ mkdir build
    $ cd build/
    
    // 不用CUDA的编译方法
    $ cmake -DCPU_ONLY=ON ..
    $ make
    
    

    2、xcode 调试出错

    1、下载脚本出错

    ./data/cifar10/get_cifar10.sh: line 9: wget: command not found
    Unzipping...
    
    $ brew install wget
    
    

    2、xcode 编译出错;

    /util/mkl_alternate.hpp:14:10: fatal error: 'cblas.h' file not found
    #include <cblas.h>
    
    
    $ brew install openblas
    
    // brew 安装没有链接好,自己手动建立软连接,包括include, lib
    $ ln -s ../Cellar/openblas/0.2.19_1/include/ openblas
    
    ln -s ../Cellar/openblas/0.2.19_1/lib/libblas.dylib libblas.dylib
    ln -s ../Cellar/openblas/0.2.19_1/lib/libopenblas.dylib libopenblas.dylib
    ln -s ../Cellar/openblas/0.2.19_1/lib/liblapack.dylib liblapack.dylib
    ln -s ../Cellar/openblas/0.2.19_1/lib/libopenblasp-r0.2.19.a libopenblasp-r0.2.19.a
    ln -s ../Cellar/openblas/0.2.19_1/lib/libopenblas.a libopenblas.a
    ln -s ../Cellar/openblas/0.2.19_1/lib/libopenblasp-r0.2.19.dylib libopenblasp-r0.2.19.dylib
    ld: library not found for -lopenblas
    
    /usr/local/include/openblas
    

    3、cifar10_quick_solver.prototxt 等修改

    http://www.jianshu.com/p/d5b4160f02d2

    Xcode Using cusom working dictionary 包括 CaffeLearning/data 目录;

    // cifar10_quick_solver.prototxt 修改如下
    net: "./cifar10_quick_train_test.prototxt"
    snapshot_prefix: "data_cifar10_quick"
    solver_mode: CPU
    
    //  cifar10_quick_train_test.prototxt 
    路径换成当前路径;如下:
    mean_file: "./mean.binaryproto"
    

    在 Xcode 中编译和调试 Caffe 的 C++ 程序 (非 Caffe 源代码)

    Compile and Debug Caffe C++ application in Xcode
    http://coldmooon.github.io/2015/08/14/compile_caffe_cpp/

    首先,caffe 的安装过程需要 glog gflags protobuf leveldb snappy 这些依赖库。那么在其 Makefile 中一定会存在这些依赖库的调用。在 Makefile 的 182 行中发现:

    LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
    
    # handle IO dependencies
    USE_LEVELDB ?= 1
    USE_LMDB ?= 1
    USE_OPENCV ?= 1
    
    ifeq ($(USE_LEVELDB), 1)
        LIBRARIES += leveldb snappy
    endif
    ifeq ($(USE_LMDB), 1)
        LIBRARIES += lmdb
    endif
    ifeq ($(USE_OPENCV), 1)
        LIBRARIES += opencv_core opencv_highgui opencv_imgproc
    
        ifeq ($(OPENCV_VERSION), 3)
            LIBRARIES += opencv_imgcodecs
        endif
    
    endif
    PYTHON_LIBRARIES ?= boost_python python2.7
    WARNINGS := -Wall -Wno-sign-compare
    
    

    可见,caffe 所需的各个依赖库都存储在 LIBRARIES 这个变量中。 caffe 编译 examples 的过程必定与 LIBRARIES 这个变量息息相关。所以,接下来专门搜索 LIBRARIES 这个关键字即可。在 426 行就会发现:

    LDFLAGS += $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(PKG_CONFIG) \
            $(foreach library,$(LIBRARIES),-l$(library))
    PYTHON_LDFLAGS := $(LDFLAGS) $(foreach library,$(PYTHON_LIBRARIES),-l$(library))
    

    相关文章

      网友评论

          本文标题:在 Xcode 中调试和研究 Caffe

          本文链接:https://www.haomeiwen.com/subject/igpmhxtx.html