因工作交接须要。 要将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 2012

  • Vim + 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的值;

  1. Caffe

    Caffe的全部message定义在$CAFFE/src/caffe/proto/caffe.proto中。

  2. Experiment

    在实验中,主要用到两个protocol buffer: solver的和model的,分别定义solver參数(学习率啥的)和model结构(网络结构)。


    技巧:

    • 冻结一层不參与训练:设置其blobs_lr=0
    • 对于图像。读取数据尽量别用HDF5Layer(由于仅仅能存float32和float64,不能用uint8, 所以太费空间)

训练基本流程:

  1. 数据处理

    法一,转换成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)
  2. 定义网络结构
  3. 配置Solver參数
  4. 训练:如 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.

$(function () {
$('pre.prettyprint code').each(function () {
var lines = $(this).text().split('\n').length;
var $numbering = $('

    ').addClass('pre-numbering').hide();
    $(this).addClass('has-numbering').parent().append($numbering);
    for (i = 1; i ').text(i));
    };
    $numbering.fadeIn(1700);
    });
    });

Caffe —— Deep learning in Practice的更多相关文章

  1. 深度学习框架Caffe —— Deep learning in Practice

    因工作交接需要, 要将caffe使用方法及整体结构描述清楚. 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家参考. 本文简单的讲几个事情: Caffe能做什么? 为什 ...

  2. (转) Deep Learning Resources

    转自:http://www.jeremydjacksonphd.com/category/deep-learning/ Deep Learning Resources Posted on May 13 ...

  3. [C3] Andrew Ng - Neural Networks and Deep Learning

    About this Course If you want to break into cutting-edge AI, this course will help you do so. Deep l ...

  4. Comparing deep learning frameworks: Tensorflow, CNTK, MXNet, & Caffe

    https://imaginghub.com/blog/10-a-comparison-of-four-deep-learning-frameworks-tensorflow-cntk-mxnet-a ...

  5. 关于深度学习(deep learning)的常见疑问 --- 谷歌大脑科学家 Caffe缔造者 贾扬清

    问答环节 问:在finetuning的时候,新问题的图像大小不同于pretraining的图像大小,只能缩放到同样的大小吗?" 答:对的:) 问:目前dl在时序序列分析中的进展如何?研究思路 ...

  6. 【深度学习Deep Learning】资料大全

    最近在学深度学习相关的东西,在网上搜集到了一些不错的资料,现在汇总一下: Free Online Books  by Yoshua Bengio, Ian Goodfellow and Aaron C ...

  7. Machine and Deep Learning with Python

    Machine and Deep Learning with Python Education Tutorials and courses Supervised learning superstiti ...

  8. Why GEMM is at the heart of deep learning

    Why GEMM is at the heart of deep learning I spend most of my time worrying about how to make deep le ...

  9. 机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)

    ##机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)---#####注:机器学习资料[篇目一](https://github.co ...

随机推荐

  1. Exploring the MapBox stack: MBTiles, TileJSON, UTFGrids and Wax

    转自:http://blog.thematicmapping.org/2012/11/exploring-mapbox-stack-mbtiles-tilejson.html In my last b ...

  2. 【Cocos2d-X开发学习笔记】第03期:渲染框架之导演类(CCDirector)的使用

    本系列学习教程使用的是cocos2d-x-2.1.4版本(截至目前为止最新稳定版) ,PC开发环境Windows7,C++开发环境VS2010 提到“导演”一词,想必读者最先联想到的是电影.作为娱乐产 ...

  3. 技术贴:解码时AVC1和H264的差别

    我一直疑问为什么有些视频解码时显示格式是:H264,大部分又是:AVC1 我在搜索编程资料时在微软的msdn上发现的: 原文:http://msdn.microsoft.com/en-us/libra ...

  4. 乐视(letv)网tkey破解

    乐视网tkey算法频繁变动,怎样才干获得她算法的源代码,以不变应万变? 本文仅仅用于技术交流.提醒各位尊重站点版权,请勿用于其他用途,否则后果自负! 使用软件 Adobe Flash Builder ...

  5. SEO市场是在扩大还是缩小 Seoer终于会变成什么?

    近期有两件全然背道而驰的事情同一时候发生.第一件事情是以SEO业务为主要业务的业者逐渐降低,很多原本是SEO的业者都纷纷转向其它业务.SEO业务反而变成副业.第二件事情是中小企业的SEO需求添加了.而 ...

  6. c# .net 读取json 字符串 与序列化和反序列化json字符串

    命名空间 using Newtonsoft.Json.Linq; JObject obj = JObject.Parse("json字符串");用 obj["" ...

  7. haml、sass简单的解释

    1. Haml 全名为 HTML Abstract Markup Language,主要就是让开发者能够使用缩排的方式撰写 HTML,做到永不忘记关 Tag 的效果. 例如:%h1= "He ...

  8. 【Oracle】ORA-01722:无效数字(控制文件最后一个字段)

    原因: 每一行物理数据最后都存在一个换行符. 如果integer或者number类型的字段位于控制文件的最后,最后其实都会有CR/LF的换行符,在用sqlldr导入时会把换行符也算作那个数字的一部分, ...

  9. spark sql 基本用法

    一.通过结构化数据创建DataFrame: publicstaticvoid main(String[] args) {    SparkConf conf = new SparkConf() .se ...

  10. JNI之HelloWorld

    什么是JNI? JNI java本地开发接口 JNI 是一个协议 这个协议用来沟通java代码和外部的本地代码(c/c++). 通过这个协议,java代码就可以调用外部的c/c++代码 外部的c/c+ ...