Caffe入门实践
学习参考资料
- caffe_intro-高翔
- Caffe Tutorial
- Caffe Model Zoo
- Awesome-Caffe
- 《深度学习:21天实战Caffe》
安装Caffe
安装依赖项
- ProtoBuffer:实现内存与非易失存储介质交换的协议接口
- Boost:“C++准标准库”
- GFLAGS:命令行参数解析
- GLOG:记录应用程序日志
- BLAS:Basic Linear Algebra Subprograms
- HDF5:一种高效存储和分发科学数据的新型数据格式
- OpenCV
- LMDB & LEVELDB:内存映射型数据库管理器,统一为 Key-Value 存储
- Snappy:用于压缩和解压缩
《深度学习:21天实战Caffe》的作者曾将 Caffe 层层外表剥离,只保留最小的必需的代码,运行一个完整的 AlexNet 模型只需不到 500 行 C++ 代码。这部分代码可以轻松移植到除 x86 外的其他平台 (GPU、ARM、DSP、Power8、FPGA等)。
下载Caffe源码,编译安装
git clone https://github.com/BVLC/caffe.git
cd caffe
mkdir build
cd build
cmake ..
make all
make install
make runtest
我在 macOS 10.14 平台上编译时出错,提示与 C++11
有关,安装如下方式修改 CMakeList.txt
后通过编译:
# ---[ Flags
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()if()
改为
# ---[ Flags
if(UNIX OR APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()if()
Caffe使用方法
caffe: command line brew
usage: caffe <command> <args>
commands:
train train or finetune a model
test score a model
device_query show GPU diagnostic information
time benchmark model execution time
Flags from /Users/zhangjixiang/Documents/GitHub/caffe/tools/caffe.cpp:
-gpu (Optional; run in GPU mode on given device IDs separated by ','.Use
'-gpu all' to run on all available GPUs. The effective training batch
size is multiplied by the number of devices.) type: string default: ""
-iterations (The number of iterations to run.) type: int32 default: 50
-level (Optional; network level.) type: int32 default: 0
-model (The model definition protocol buffer text file.) type: string
default: ""
-phase (Optional; network phase (TRAIN or TEST). Only used for 'time'.)
type: string default: ""
-sighup_effect (Optional; action to take when a SIGHUP signal is received:
snapshot, stop or none.) type: string default: "snapshot"
-sigint_effect (Optional; action to take when a SIGINT signal is received:
snapshot, stop or none.) type: string default: "stop"
-snapshot (Optional; the snapshot solver state to resume training.)
type: string default: ""
-solver (The solver definition protocol buffer text file.) type: string
default: ""
-stage (Optional; network stages (not to be confused with phase), separated
by ','.) type: string default: ""
-weights (Optional; the pretrained weights to initialize finetuning,
separated by ','. Cannot be set simultaneously with snapshot.)
type: string default: ""
安装和训练 Faster-RCNN 的 bug 很多,不过大部分可以通过 Google 解决。
Faster-RCNN+ZF用自己的数据集训练模型(Python版本)
针对只使用 CPU 训练 Faster-RCNN 的情况,需要把默认的 GPU 设置为 CPU。还需要添加 4 个 C++ 源文件用 CPU 实现 GPU 的功能。需要修改的文件包括: