在 Xcode 中調試和研究 Caffe

先記錄,后面再整理;

在 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.lxweimin.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))
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容