深度学习框架Caffe —— Deep learning in Practice
因工作交接需要, 要将caffe使用方法及整体结构描述清楚。 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家参考。
本文简单的讲几个事情:
- Caffe能做什么?
- 为什么选择caffe?
- 环境
- 整体结构
- Protocol buffer
- 训练基本流程
- Python中训练
- Debug
Caffe能做什么?
- 定义网络结构
- 训练网络
- C++/CUDA 写的结构
- cmd/python/Matlab接口
- CPU/GPU工作模式
- 给了一些参考模型&pretrain了的weights
为什么选择caffe?
- 模块化做的好
- 简单:修改结构无需该代码
- 开源:共同维护开源代码
环境:
$ lsb_release -a
Distributor ID: Ubuntu
Description: Ubuntu 12.04.4 LTS
Release: 12.04
Codename: precise$ cat /proc/version
Linux version 3.2.0-29-generic (buildd@allspice) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012Vim + Taglist + Cscope
整体结构:
定义CAFFE为caffe跟目录,caffe的核心代码都在$CAFFE/src/caffe 下,主要有以下部分:net, blob, layer, solver.
net.cpp:
net定义网络, 整个网络中含有很多layers, net.cpp负责计算整个网络在训练中的forward, backward过程, 即计算forward/backward 时各layer的gradient。layers:
在$CAFFE/src/caffe/layers中的层,在protobuffer (.proto文件中定义message类型,.prototxt或.binaryproto文件中定义message的值) 中调用时包含属性name, type(data/conv/pool…), connection structure (input blobs and output blobs),layer-specific parameters(如conv层的kernel大小)。定义一个layer需要定义其setup, forward 和backward过程。blob.cpp:
net中的数据和求导结果通过4维的blob传递。一个layer有很多blobs, e.g,- 对data,weight blob大小为Number * Channels * Height * Width, 如256*3*224*224;
- 对conv层,weight blob大小为 Output 节点数 * Input 节点数 * Height * Width,如AlexNet第一个conv层的blob大小为96 x 3 x 11 x 11;
- 对inner product 层, weight blob大小为 1 * 1 * Output节点数 * Input节点数; bias blob大小为1 * 1 * 1 * Output节点数( conv层和inner product层一样,也有weight和bias,所以在网络结构定义中我们会看到两个blobs_lr,第一个是weights的,第二个是bias的。类似地,weight_decay也有两个,一个是weight的,一个是bias的);
blob中,mutable_cpu/gpu_data() 和cpu/gpu_data()用来管理memory,cpu/gpu_diff()和 mutable_cpu/gpu_diff()用来计算求导结果。
slover.cpp:
结合loss,用gradient更新weights。主要函数:
Init(),
Solve(),
ComputeUpdateValue(),
Snapshot(), Restore(),//快照(拷贝)与恢复 网络state
Test();在solver.cpp中有3中solver,即3个类:AdaGradSolver, SGDSolver和NesterovSolver可供选择。
关于loss,可以同时有多个loss,可以加regularization(L1/L2);
Protocol buffer:
上面已经将过, protocol buffer在 .proto文件中定义message类型,.prototxt或.binaryproto文件中定义message的值;
Caffe
Caffe的所有message定义在$CAFFE/src/caffe/proto/caffe.proto中。Experiment
在实验中,主要用到两个protocol buffer: solver的和model的,分别定义solver参数(学习率啥的)和model结构(网络结构)。技巧:
- 冻结一层不参与训练:设置其blobs_lr=0
- 对于图像,读取数据尽量别用HDF5Layer(因为只能存float32和float64,不能用uint8, 所以太费空间)
训练基本流程:
- 数据处理
法一,转换成caffe接受的格式:lmdb, leveldb, hdf5 / .mat, list of images, etc.;法二,自己写数据读取层(如https://github.com/tnarihi/tnarihi-caffe-helper/blob/master/python/caffe_helper/layers/data_layers.py) - 定义网络结构
- 配置Solver参数
- 训练:如 caffe train -solver solver.prototxt -gpu 0
在python中训练:
Document & Examples: https://github.com/BVLC/caffe/pull/1733
核心code:
- $CAFFE/python/caffe/_caffe.cpp
定义Blob, Layer, Net, Solver类 - $CAFFE/python/caffe/pycaffe.py
Net类的增强功能
Debug:
- 在Make.config中设置DEBUG := 1
- 在solver.prototxt中设置debug_info: true
- 在python/Matlab中察看forward & backward一轮后weights的变化
经典文献:
[ DeCAF ] J. Donahue, Y. Jia, O. Vinyals, J. Hoffman, N. Zhang, E. Tzeng, and T. Darrell. Decaf: A deep convolutional activation feature for generic visual recognition. ICML, 2014.
[ R-CNN ] R. Girshick, J. Donahue, T. Darrell, and J. Malik. Rich feature hierarchies for accurate object detection and semantic segmentation. CVPR, 2014.
[ Zeiler-Fergus Visualizing] M. Zeiler and R. Fergus. visualizing and understanding convolutional networks. ECCV, 2014.
[ LeNet ] Y. LeCun, L. Bottou, Y. Bengio, and P. Haffner. Gradient-based learning applied to document recognition. IEEE, 1998.
[ AlexNet ] A. Krizhevsky, I. Sutskever, and G. Hinton. Imagenet classification with deep convolutional neural networks. NIPS, 2012.
[ OverFeat ] P. Sermanet, D. Eigen, X. Zhang, M. Mathieu, R. Fergus, and Y. LeCun. Overfeat: Integrated recognition, localization and detection using convolutional networks. ICLR, 2014.
[ Image-Style (Transfer learning) ] S. Karayev, M. Trentacoste, H. Han, A. Agarwala, T. Darrell, A. Hertzmann, H. Winnemoeller. Recognizing Image Style. BMVC, 2014.
[ Karpathy14 ] A. Karpathy, G. Toderici, S. Shetty, T. Leung, R. Sukthankar, and L. Fei-Fei. Large-scale video classification with convolutional neural networks. CVPR, 2014.
[ Sutskever13 ] I. Sutskever. Training Recurrent Neural Networks. PhD thesis, University of Toronto, 2013.
[ Chopra05 ] S. Chopra, R. Hadsell, and Y. LeCun. Learning a similarity metric discriminatively, with application to face verification. CVPR, 2005.
from: http://blog.csdn.net/abcjennifer/article/details/46424949
深度学习框架Caffe —— Deep learning in Practice的更多相关文章
- 贝叶斯深度学习(bayesian deep learning)
本文简单介绍什么是贝叶斯深度学习(bayesian deep learning),贝叶斯深度学习如何用来预测,贝叶斯深度学习和深度学习有什么区别.对于贝叶斯深度学习如何训练,本文只能大致给个介绍. ...
- 深度学习概述教程--Deep Learning Overview
引言 深度学习,即Deep Learning,是一种学习算法(Learning algorithm),亦是人工智能领域的一个重要分支.从快速发展到实际应用,短短几年时间里, ...
- 深度学习框架Caffe的编译安装
深度学习框架caffe特点,富有表达性.快速.模块化.下面介绍caffe如何在Ubuntu上编译安装. 1. 前提条件 安装依赖的软件包: CUDA 用来使用GPU模式计算. 建议使用 7.0 以上最 ...
- 深度学习框架-caffe安装-环境[Mac OSX 10.12]
深度学习框架-caffe安装 [Mac OSX 10.12] [参考资源] 1.英文原文:(使用GPU) [http://hoondy.com/2015/04/03/how-to-install-ca ...
- 深度学习框架-caffe安装-Mac OSX 10.12
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px ".PingFang SC"; color: #454545 } p.p2 ...
- 深度学习加速器堆栈Deep Learning Accelerator Stack
深度学习加速器堆栈Deep Learning Accelerator Stack 通用张量加速器(VTA)是一种开放的.通用的.可定制的深度学习加速器,具有完整的基于TVM的编译器堆栈.设计了VTA来 ...
- 贾扬清分享_深度学习框架caffe
Caffe是一个清晰而高效的深度学习框架,其作者是博士毕业于UC Berkeley的 贾扬清,目前在Google工作.本文是根据机器学习研究会组织的online分享的交流内容,简单的整理了一下. 目录 ...
- 深度学习论文笔记-Deep Learning Face Representation from Predicting 10,000 Classes
来自:CVPR 2014 作者:Yi Sun ,Xiaogang Wang,Xiaoao Tang 题目:Deep Learning Face Representation from Predic ...
- 深度学习框架caffe/CNTK/Tensorflow/Theano/Torch的对比
在单GPU下,所有这些工具集都调用cuDNN,因此只要外层的计算或者内存分配差异不大其性能表现都差不多. Caffe: 1)主流工业级深度学习工具,具有出色的卷积神经网络实现.在计算机视觉领域Caff ...
随机推荐
- Keystore概念,Keytool工具使用
几个概念 keystore是一个密码保护的文件,用来存储密钥和证书(也就是说,keystore中存储的有两类型entries):这个文件(默认的)位于你的home目录,也就是你登录到操作系统的用户名的 ...
- max_flow(Ford-Fulkerson) 分类: ACM TYPE 2014-09-02 01:50 110人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include<queue> usi ...
- 一个包的TcpServer流程
上次说到对于那种有内容的包 bool TCPServer::on_receive_data(int channel_id, void* data, int len) { packet pkt; { p ...
- Redis Master/Slave 实践
本次我们将模拟 Master(1) + Slave(4) 的场景,并通过ASP.NET WEB API进行数据的提交及查询,监控 Redis Master/Slave 数据分发情况,只大致概述,不会按 ...
- WARNING: Calls to any function that may require a gradient calculation inside a conditional block may return undefined results
GLES2.0: Some device will give a warning on compling shaders(yet the compling will succeed), and the ...
- APM 终端用户体验监控分析(上)
一.前言 理解用户体验是从终端用户角度了解应用交付质量的关键,这是考量业务健康运转的潜在因素.捕获此类数据的方法各种各样,具体的实现途径由应用.基础设施架构以及管理者和管理过程决定. 二.终端用户监控 ...
- Codeforces 452E Three Strings(后缀自动机)
上学期很认真地学了一些字符串的常用工具,各种 suffix structre,但是其实对后缀自动机这个部分是理解地不太透彻的,以致于看了师兄A这题的代码后,我完全看不懂,于是乎重新看回一些学习后缀自动 ...
- POJ 1001 Exponentiation(JAVA,BigDecimal->String)
题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static voi ...
- POJ 2186
Popular Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22189 Accepted: 9076 Des ...
- DMS平台从.NET 1.1升级到.NET 4.0的升级步骤
1)复制新增的项目到4.0平台解决方案对应目录,添加到到解决方案中:2)合并公共文件(比如修改了FormMain主界面.基础类库.售后界面的修改)3)控件的修订(Dev少数属性可能需要手工调整为新的方 ...