目录

  • 1. 初见LeNet原始模型
  • 2. Caffe LeNet的网络结构
  • 3. 逐层理解Caffe LeNet
    • 3.1 Data Layer
    • 3.2 Conv1 Layer
    • 3.3 Pool1 Layer
    • 3.4 Conv2 Layer
    • 3.5 Pool2 Layer
    • 3.6 Ip1 Layer
    • 3.7 Relu1 Layer
    • 3.8 Ip2 Layer
    • 3.9 Loss Layer

1. 初见LeNet原始模型

Fig.1. Architecture of original LeNet-5.

图片来源: Lecun, et al., Gradient-based learning applied to document recognition, P IEEE, vol. 86, no. 11, 1998, pp. 2278-2324.

在这篇图片的论文中,详细描述了LeNet-5的结构。

这里不对LeNet-5原始模型进行讨论。可以参考这些资料:

http://blog.csdn.net/qiaofangjie/article/details/16826849

http://blog.csdn.net/xuanyuansen/article/details/41800721

回到顶部(go to top)

2. Caffe LeNet的网络结构

他山之石,可以攻玉。本来是准备画出Caffe LeNet的图的,但发现已经有人做了,并且画的很好,就直接拿过来辅助理解了。

第3部分图片来源:http://www.2cto.com/kf/201606/518254.html

先从整体上感知Caffe LeNet的拓扑图,由于Caffe中定义网络的结构采用的是bottom&top这种上下结构,所以这里的图也采用这种方式展现出来,更加方便理解。

Fig.2. Architecture of caffe LeNet.

From bottom to top: Data Layer, conv1, pool1, conv2, pool2, ip1, relu1, ip2, [accuracy]loss.

本节接下来将按照这个顺序依次理解Caffe LeNet的网络结构。

3. 逐层理解Caffe LeNet
本节将采用定义与图解想结合的方式逐层理解Caffe LeNet的结构。3.1 Data Layer
#==============定义TRAIN的数据层============================================
layer { name: "mnist" #定义该层的名字type: "Data"  #该层的类型是数据top: "data"   #该层生成一个data blobtop: "label"  #该层生成一个label blobinclude {phase: TRAIN #说明该层只在TRAIN阶段使用}transform_param {scale: 0.00390625 #数据归一化系数,1/256,归一到[0,1)}data_param {source: "E:/MyCode/DL/caffe-master/examples/mnist/mnist_train_lmdb" #训练数据的路径batch_size: 64 #批量处理的大小backend: LMDB}
}
#==============定义TEST的数据层============================================
layer { name: "mnist"type: "Data"top: "data"top: "label"include {phase: TEST #说明该层只在TEST阶段使用}transform_param {scale: 0.00390625}data_param {source: "E:/MyCode/DL/caffe-master/examples/mnist/mnist_test_lmdb" #测试数据的路径batch_size: 100backend: LMDB}
}
2Fig.3. Architecture of data layer.Fig.3 是train情况下,数据层读取lmdb数据,每次读取64条数据,即N=64。Caffe中采用4D表示,N*C*H*W(Num*Channels*Height*Width)。3.2 Conv1 Layer
#==============定义卷积层1=============================
layer {name: "conv1"       #该层的名字conv1,即卷积层1type: "Convolution" #该层的类型是卷积层bottom: "data"      #该层使用的数据是由数据层提供的data blobtop: "conv1"        #该层生成的数据是conv1param {lr_mult: 1        #weight learning rate(简写为lr)权值的学习率,1表示该值是lenet_solver.prototxt中base_lr: 0.01的1倍}param {lr_mult: 2        #bias learning rate偏移值的学习率,2表示该值是lenet_solver.prototxt中base_lr: 0.01的2倍}convolution_param {num_output: 20    #产生20个输出通道kernel_size: 5    #卷积核的大小为5*5stride: 1         #卷积核移动的步幅为1weight_filler {type: "xavier"  #xavier算法,根据输入和输出的神经元的个数自动初始化权值比例}bias_filler {type: "constant"  #将偏移值初始化为“稳定”状态,即设为默认值0}}
}
3Fig.4. Architecture of conv1 layer.conv1的数据变化的情况:batch_size*1*28*28->batch_size*20*24*243.3 Pool1 Layer
#==============定义池化层1=============================
layer {name: "pool1"type: "Pooling"bottom: "conv1"     #该层使用的数据是由conv1层提供的conv1top: "pool1"        #该层生成的数据是pool1pooling_param {pool: MAX         #采用最大值池化kernel_size: 2    #池化核大小为2*2stride: 2         #池化核移动的步幅为2,即非重叠移动}
}
4Fig.5. Architecture of pool1 layer.池化层1过程数据变化:batch_size*20*24*24->batch_size*20*12*123.4 Conv2 Layer
#==============定义卷积层2=============================
layer {name: "conv2"type: "Convolution"bottom: "pool1"top: "conv2"param {lr_mult: 1}param {lr_mult: 2}convolution_param {num_output: 50kernel_size: 5stride: 1weight_filler {type: "xavier"}bias_filler {type: "constant"}}
}
conv2层的图与Fig.4 类似,卷积层2过程数据变化:batch_size*20*12*12->batch_size*50*8*8。3.5 Pool2 Layer
#==============定义池化层2=============================
layer {name: "pool2"type: "Pooling"bottom: "conv2"top: "pool2"pooling_param {pool: MAXkernel_size: 2stride: 2}
}
pool2层图与Fig.5类似,池化层2过程数据变化:batch_size*50*8*8->batch_size*50*4*4。3.6 Ip1 Layer
#==============定义全连接层1=============================
layer {name: "ip1"type: "InnerProduct" #该层的类型为全连接层bottom: "pool2"top: "ip1"param {lr_mult: 1}param {lr_mult: 2}inner_product_param {num_output: 500 #有500个输出通道weight_filler {type: "xavier"}bias_filler {type: "constant"}}
}
5Fig.6. Architecture of ip11 layer.ip1过程数据变化:batch_size*50*4*4->batch_size*500*1*1。此处的全连接是将C*H*W转换成1D feature vector,即800->500.3.7 Relu1 Layer
#==============定义ReLU1层=============================
layer {name: "relu1"type: "ReLU"bottom: "ip1"top: "ip1"
}
6
Fig.7. Architecture of relu1 layer.
ReLU1层过程数据变化:batch_size*500*1*1->batch_size*500*1*13.8 Ip2 Layer
#==============定义全连接层2============================
layer {name: "ip2"type: "InnerProduct"bottom: "ip1"top: "ip2"param {lr_mult: 1}param {lr_mult: 2}inner_product_param {num_output: 10          #10个输出数据,对应0-9十个数字weight_filler {type: "xavier"}bias_filler {type: "constant"}}
}
ip2过程数据变化:batch_size*500*1*1->batch_size*10*1*13.9 Loss Layer
#==============定义损失函数层============================
layer {name: "loss"type: "SoftmaxWithLoss"bottom: "ip2"bottom: "label"top: "loss"
}
7Fig.8. Architecture of loss layer.损失层过程数据变化:batch_size*10*1*1->batch_size*10*1*1note:注意到caffe LeNet中有一个accuracy layer的定义,这是输出测试结果的层。回到顶部(go to top)
4. Caffe LeNet的完整定义
name: "LeNet" #定义网络的名字
#==============定义TRAIN的数据层============================================
layer { name: "mnist" #定义该层的名字type: "Data"  #该层的类型是数据top: "data"   #该层生成一个data blobtop: "label"  #该层生成一个label blobinclude {phase: TRAIN #说明该层只在TRAIN阶段使用}transform_param {scale: 0.00390625 #数据归一化系数,1/256,归一到[0,1)}data_param {source: "E:/MyCode/DL/caffe-master/examples/mnist/mnist_train_lmdb" #训练数据的路径batch_size: 64 #批量处理的大小backend: LMDB}
}
#==============定义TEST的数据层============================================
layer { name: "mnist"type: "Data"top: "data"top: "label"include {phase: TEST #说明该层只在TEST阶段使用}transform_param {scale: 0.00390625}data_param {source: "E:/MyCode/DL/caffe-master/examples/mnist/mnist_test_lmdb" #测试数据的路径batch_size: 100backend: LMDB}
}
#==============定义卷积层1=============================
layer {name: "conv1"       #该层的名字conv1,即卷积层1type: "Convolution" #该层的类型是卷积层bottom: "data"      #该层使用的数据是由数据层提供的data blobtop: "conv1"        #该层生成的数据是conv1param {lr_mult: 1        #weight learning rate(简写为lr)权值的学习率,1表示该值是lenet_solver.prototxt中base_lr: 0.01的1倍}param {lr_mult: 2        #bias learning rate偏移值的学习率,2表示该值是lenet_solver.prototxt中base_lr: 0.01的2倍}convolution_param {num_output: 20    #产生20个输出通道kernel_size: 5    #卷积核的大小为5*5stride: 1         #卷积核移动的步幅为1weight_filler {type: "xavier"  #xavier算法,根据输入和输出的神经元的个数自动初始化权值比例}bias_filler {type: "constant"  #将偏移值初始化为“稳定”状态,即设为默认值0}}
}#卷积过程数据变化:batch_size*1*28*28->batch_size*20*24*24
#==============定义池化层1=============================
layer {name: "pool1"type: "Pooling"bottom: "conv1"     #该层使用的数据是由conv1层提供的conv1top: "pool1"        #该层生成的数据是pool1pooling_param {pool: MAX         #采用最大值池化kernel_size: 2    #池化核大小为2*2stride: 2         #池化核移动的步幅为2,即非重叠移动}
}#池化层1过程数据变化:batch_size*20*24*24->batch_size*20*12*12
#==============定义卷积层2=============================
layer {name: "conv2"type: "Convolution"bottom: "pool1"top: "conv2"param {lr_mult: 1}param {lr_mult: 2}convolution_param {num_output: 50kernel_size: 5stride: 1weight_filler {type: "xavier"}bias_filler {type: "constant"}}
}#卷积层2过程数据变化:batch_size*20*12*12->batch_size*50*8*8
#==============定义池化层2=============================
layer {name: "pool2"type: "Pooling"bottom: "conv2"top: "pool2"pooling_param {pool: MAXkernel_size: 2stride: 2}
}#池化层2过程数据变化:batch_size*50*8*8->batch_size*50*4*4
#==============定义全连接层1=============================
layer {name: "ip1"type: "InnerProduct" #该层的类型为全连接层bottom: "pool2"top: "ip1"param {lr_mult: 1}param {lr_mult: 2}inner_product_param {num_output: 500 #有500个输出通道weight_filler {type: "xavier"}bias_filler {type: "constant"}}
}#全连接层1过程数据变化:batch_size*50*4*4->batch_size*500*1*1
#==============定义ReLU1层=============================
layer {name: "relu1"type: "ReLU"bottom: "ip1"top: "ip1"
}#ReLU1层过程数据变化:batch_size*500*1*1->batch_size*500*1*1
#==============定义全连接层2============================
layer {name: "ip2"type: "InnerProduct"bottom: "ip1"top: "ip2"param {lr_mult: 1}param {lr_mult: 2}inner_product_param {num_output: 10          #10个输出数据,对应0-9十个数字weight_filler {type: "xavier"}bias_filler {type: "constant"}}
}#全连接层2过程数据变化:batch_size*500*1*1->batch_size*10*1*1
#==============定义显示准确率结果层============================
layer {name: "accuracy"type: "Accuracy"bottom: "ip2"bottom: "label"top: "accuracy"include {phase: TEST}
}
#==============定义损失函数层============================
layer {name: "loss"type: "SoftmaxWithLoss"bottom: "ip2"bottom: "label"top: "loss"
}#损失层过程数据变化:batch_size*10*1*1->batch_size*10*1*1

理解Caffe的网络模型相关推荐

  1. 使用拓扑数据分析理解卷积神经网络模型的工作过程

    摘要: 神经网络功能强大,但内部复杂且不透明,被称为黑匣子工具.使用拓扑数据分析以紧凑且可理解的方式描述卷积神经网络的功能和学习过程. 1.简介 神经网络在各种数据方面处理上已经取得了很大的成功,包括 ...

  2. caffe 创建网络模型

    要点 1.在caffe中,我们通常说一个模型,其实就是一个网络,一个Net 2.在caffe2中,我们通常使用modelHelper来代表一个model,而这个model包含多个Net,就像我们前面看 ...

  3. 深度学习框架Caffe源码解析

    作者:薛云峰(https://github.com/HolidayXue),主要从事视频图像算法的研究, 本文来源微信公众号:深度学习大讲堂.  原文:深度学习框架Caffe源码解析  欢迎技术投稿. ...

  4. caffe源码c++学习笔记

    转载自:深度学习(七)caffe源码c++学习笔记 - hjimce的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/hjimce/article/details/ ...

  5. 深度学习(七)caffe源码c++学习笔记

    caffe源码c++学习笔记 原文地址:http://blog.csdn.net/hjimce/article/details/48933845 作者:hjimce 一.预测分类 最近几天为了希望深入 ...

  6. 【神经网络与深度学习】Caffe使用step by step:使用自己数据对已经训练好的模型进行finetuning...

    在经过前面Caffe框架的搭建以及caffe基本框架的了解之后,接下来就要回到正题:使用caffe来进行模型的训练. 但如果对caffe并不是特别熟悉的话,从头开始训练一个模型会花费很多时间和精力,需 ...

  7. caffe中的fine-tuning

    caffe finetune两种修改网络结构prototxt方法 第一种方法:将原来的prototxt中所有的fc8改为fc8-re.(若希望修改层的学习速度比其他层更快一点,可以将lr_mult改为 ...

  8. 深度学习_21天实战Caffe.pdf

    深度学习_21天实战Caffe.pdf 原 深度学习21天实战caffe学习笔记<1:深度学习的过往> 1. 深度学习DL: 1.1.有监督学习.无监督学习.过拟合.训练样本.泛化.训练集 ...

  9. 卷积神经网络模型如何辨识裸体图片

    著名人工智能公司Clarifai公司近日推出了识别成人内容的模型和API NSFW,该模型能够很准确地识别含有裸体和半裸的图片和视频,在Clarifai的这篇博文中,作者用裸体检测问题来展示训练现代版 ...

最新文章

  1. Bochs调试Linux内核 - 定位内核中的变量或数据结构
  2. Span元素的 width属性 无效果原因及解决方案
  3. centos安装Oracle virtual box
  4. 火狐打印预览_将打印和打印预览命令添加到Firefox的上下文菜单
  5. [神奇的问题啊,GetProcAddress一个不存在的API时,返回非空值,且指向另一个API]谜团解开,错不在GetProcAddress...
  6. Zookeeper基础简介
  7. java和xampp_XAMPP和Bugfree详细教程
  8. Ubuntu16.04下 编译安装 Tensorflow
  9. 前端图片文字复制粘贴功能
  10. 基于STM8的TM1640驱动程序(附八段数码管配置工具)
  11. visual basic是不是计算机语言,辉煌不再!Microsoft计划结束Visual Basic编程语言
  12. 如何写好一篇科技论文?
  13. 乱码文件删除不了的解决方法(需要everyone权限)
  14. Xenu's Link Sleuth 的使用
  15. SpringMvc中的校验框架@valid和@validation的概念及相关使用 和BindingResult bindingResult...
  16. application配置文件读取!
  17. BZOJ 1002 1003 1007 被屠记录
  18. 【傲腾观察室】英特尔® 傲腾™技术,助力金融行业数据库价值迸发!
  19. 浏览器被万恶的hao123锁定主页
  20. ☆ZigBee的碎片化

热门文章

  1. 如何改善虚幻引擎中的游戏线程CPU性能表现
  2. asterisk1.8 Makefile分析 (2)
  3. 16进制字符串转化为10进制数
  4. hdfs 多个文件合并_hadoop学习笔记3 hadoop程序将本地文件夹中多个文件,合并为一个文件并上传到hdfs中--梦飞翔的地方(梦翔天空)...
  5. arcgis将小于0的数值设置成0.01
  6. 论文中地层岩性和岩组描述总结
  7. spectral安装
  8. 26享元模式(Flyweight Pattern)
  9. HDFS--分布式文件系统
  10. 【Python CheckiO 题解】House Password