浅谈caffe中train_val.prototxt和deploy.prototxt文件的区别

标签: caffe深度学习CaffeNet
2016-11-02 16:10 1203人阅读 评论(1) 收藏 举报
 分类:
Caffe(2) 

版权声明:本文为博主原创文章,未经博主允许不得转载。

在刚开始学习的时候,觉得train_val.prototxt文件和deploy.prototxt文件很相似,然后当时想尝试利用deploy.prototxt还原出train_val.prototxt文件,所以就进行了一下对比,水平有限,可能很多地方说的不到位,希望大神们指点批评~~


本文以CaffeNet为例:
1. train_val.prototxt 
首先,train_val.prototxt文件是网络配置文件。该文件是在训练的时候用的。
2.deploy.prototxt
该文件是在测试时使用的文件。
区别:
首先deploy.prototxt文件都是在train_val.prototxt文件的基础上删除了一些东西,所形成的。
由于两个文件的性质,train_val.prototxt文件里面训练的部分都会在deploy.prototxt文件中删除。
在train_val.prototxt文件中,开头要加入一下训练设置文件和准备文件。例如,transform_param中的mirror: true(开启镜像);crop_size: ***(图像尺寸);mean_file: ""(求解均值的文件),还有data_param中的source:""(处理过得数据训练集文件);batch_size: ***(训练图片每批次输入图片的数量);backend: LMDB(数据格式设置)。
然后接下来,训练的时候还有一个测试的设置,测试和训练模式的设置通过一个include{phase: TEST/TRAIN}来设置。接下来就是要设置TEST模块内容。然后其他设置跟上面一样,里面有个batch_size可以调小一点,因为测试的话不需要特别多的图片数量。
而以上这一块的内容在deploy里表现出来的只有一个数据层的设置。只需设置name,type,top,input_param这些即可。
接下来,第一个卷积层的设置,train_val.prototxt文件中多了param(反向传播学习率的设置),这里需要设置两个param一个时weight的学习率,一个时bias的学习率,其中一般bias的学习率是weight学习率的两倍。然后就是设置convolution_param,但是在train_val里面需要有对weight_filler的初始化和对bias_filler的初始化。
然后就是设置激活激活函数。这一块由于没有初始化,所以两个文件都是一样的。
再接下来就是池化层,由于池化就是降低分辨率,所以这两边是一样的,只需要设置kernel_size,stride,pool即可。无需参数的初始化。
再下来时LRN层,该层的全称是Local Response Normalization(局部响应值归一化),该层的作用就是对局部输入进行一个归一化操作,不过现在有论文表明,这一层加不加对结果影响不是很大。但这一层的定义都是相同的。
再接下来就是"conv2"、"relu2"、"pool2"、"LRN2"这样的循环,具体跟之前说的一样,train_val主要多的就是参数的初始化和学习率的设置。
在第五个卷积层之后,进入了"fc6"层,该层是全连接层,这里train_val里面还是多两个param学习率的设置,和weight_filler、bias_filler的初始化设置,而两者共同的是有一个输出向量元素个数的设置:inner_product_param。
再接下来就是激活函数RELU。
再接下来就是Dropout层,该层的目的就是为了防止模型过拟合。这其中有一个dropout_ration的设置一般为0.5即可。
再接下来就是"fc7",这一层跟"fc6"相同。然后就是"relu7"、"drop7"都是相同的。然后就是"fc8"也与之前相同。
再接下来就是Accuracy,这个层是用来计算网络输出相对目标值的准确率,它实际上并不是一个损失层,所以没有反传操作。但是在caffe官网中,它在损失层这一部分。所以在deploy.prototxt文件中,这一层的定义是没有的。
再接下来train_val的最后一个层是"SoftmaxWithLoss"层,也是简单的定义了name,type,bottom,top就完了。而这一块的内容也不在deploy.prototxt文件中。
而在deploy.prototxt文件中直接定义了一个type:"Softmax"。
通过对CaffeNet这两个文件的查看发现deploy.prototxt文件和train_val.prototxt文件之间的差异在很多层里面牵扯到训练部分的都会被删除,然后就是反向传播训练部分会被删除。
其中,这里面有一个区别在里头,就是为什么train_val里面的是SoftmaxWithLoss而deploy里面的是Softmax层(两个都是损失层,都没有任何参数):
这里面其实都是softmax回归的应用,只是在定义成Softmax时直接计算了概率室友forward部分,而在SoftmaxWithLoss部分时是还有backward的部分。所以这里就出现了区别,具体的区别可以看这两个文件的C++定义。
下表左边的是train_val.prototxt文件,右边是deploy.prototxt文件。
name: "CaffeNet"
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TRAIN
}
transform_param {
mirror: true
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: true
# }
data_param {
source: "examples/imagenet/ilsvrc12_train_lmdb"
batch_size: 256
backend: LMDB
}
}
layer {
name: "data"
type: "Data"
top: "data"
top: "label"
include {
phase: TEST
}
transform_param {
mirror: false
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
}
# mean pixel / channel-wise mean instead of mean image
# transform_param {
# crop_size: 227
# mean_value: 104
# mean_value: 117
# mean_value: 123
# mirror: false
# }
data_param {
source: "examples/imagenet/ilsvrc12_val_lmdb"
batch_size: 50
backend: LMDB
}
}
layer {
name: "conv1"
type: "Convolution"
bottom: "data"
top: "conv1"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "conv1"
top: "conv1"
}
layer {
name: "pool1"
type: "Pooling"
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "norm1"
type: "LRN"
bottom: "pool1"
top: "norm1"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "norm1"
top: "conv2"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 2
kernel_size: 5
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu2"
type: "ReLU"
bottom: "conv2"
top: "conv2"
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "norm2"
type: "LRN"
bottom: "pool2"
top: "norm2"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layer {
name: "conv3"
type: "Convolution"
bottom: "norm2"
top: "conv3"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "relu3"
type: "ReLU"
bottom: "conv3"
top: "conv3"
}
layer {
name: "conv4"
type: "Convolution"
bottom: "conv3"
top: "conv4"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu4"
type: "ReLU"
bottom: "conv4"
top: "conv4"
}
layer {
name: "conv5"
type: "Convolution"
bottom: "conv4"
top: "conv5"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
group: 2
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu5"
type: "ReLU"
bottom: "conv5"
top: "conv5"
}
layer {
name: "pool5"
type: "Pooling"
bottom: "conv5"
top: "pool5"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layer {
name: "fc6"
type: "InnerProduct"
bottom: "pool5"
top: "fc6"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu6"
type: "ReLU"
bottom: "fc6"
top: "fc6"
}
layer {
name: "drop6"
type: "Dropout"
bottom: "fc6"
top: "fc6"
dropout_param {
dropout_ratio: 0.5
}
}
layer {
name: "fc7"
type: "InnerProduct"
bottom: "fc6"
top: "fc7"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 4096
weight_filler {
type: "gaussian"
std: 0.005
}
bias_filler {
type: "constant"
value: 1
}
}
}
layer {
name: "relu7"
type: "ReLU"
bottom: "fc7"
top: "fc7"
}
layer {
name: "drop7"
type: "Dropout"
bottom: "fc7"
top: "fc7"
dropout_param {
dropout_ratio: 0.5
}
}
layer {
name: "fc8"
type: "InnerProduct"
bottom: "fc7"
top: "fc8"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
inner_product_param {
num_output: 1000
weight_filler {
type: "gaussian"
std: 0.01
}
bias_filler {
type: "constant"
value: 0
}
}
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc8"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc8"
bottom: "label"
top: "loss"
}
name: "CaffeNet"
layer {
  name: "data"
  type: "Input"
  top: "data"
  input_param { shape: { dim: 10 dim: 3 dim: 227 dim: 227 } }
}
layer {
  name: "conv1"
  type: "Convolution"
  bottom: "data"
  top: "conv1"
  convolution_param {
    num_output: 96
    kernel_size: 11
    stride: 4
  }
}
layer {
  name: "relu1"
  type: "ReLU"
  bottom: "conv1"
  top: "conv1"
}
layer {
  name: "pool1"
  type: "Pooling"
  bottom: "conv1"
  top: "pool1"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "norm1"
  type: "LRN"
  bottom: "pool1"
  top: "norm1"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv2"
  type: "Convolution"
  bottom: "norm1"
  top: "conv2"
  convolution_param {
    num_output: 256
    pad: 2
    kernel_size: 5
    group: 2
  }
}
layer {
  name: "relu2"
  type: "ReLU"
  bottom: "conv2"
  top: "conv2"
}
layer {
  name: "pool2"
  type: "Pooling"
  bottom: "conv2"
  top: "pool2"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "norm2"
  type: "LRN"
  bottom: "pool2"
  top: "norm2"
  lrn_param {
    local_size: 5
    alpha: 0.0001
    beta: 0.75
  }
}
layer {
  name: "conv3"
  type: "Convolution"
  bottom: "norm2"
  top: "conv3"
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
  }
}
layer {
  name: "relu3"
  type: "ReLU"
  bottom: "conv3"
  top: "conv3"
}
layer {
  name: "conv4"
  type: "Convolution"
  bottom: "conv3"
  top: "conv4"
  convolution_param {
    num_output: 384
    pad: 1
    kernel_size: 3
    group: 2
  }
}
layer {
  name: "relu4"
  type: "ReLU"
  bottom: "conv4"
  top: "conv4"
}
layer {
  name: "conv5"
  type: "Convolution"
  bottom: "conv4"
  top: "conv5"
  convolution_param {
    num_output: 256
    pad: 1
    kernel_size: 3
    group: 2
  }
}
layer {
  name: "relu5"
  type: "ReLU"
  bottom: "conv5"
  top: "conv5"
}
layer {
  name: "pool5"
  type: "Pooling"
  bottom: "conv5"
  top: "pool5"
  pooling_param {
    pool: MAX
    kernel_size: 3
    stride: 2
  }
}
layer {
  name: "fc6"
  type: "InnerProduct"
  bottom: "pool5"
  top: "fc6"
  inner_product_param {
    num_output: 4096
  }
}
layer {
  name: "relu6"
  type: "ReLU"
  bottom: "fc6"
  top: "fc6"
}
layer {
  name: "drop6"
  type: "Dropout"
  bottom: "fc6"
  top: "fc6"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc7"
  type: "InnerProduct"
  bottom: "fc6"
  top: "fc7"
  inner_product_param {
    num_output: 4096
  }
}
layer {
  name: "relu7"
  type: "ReLU"
  bottom: "fc7"
  top: "fc7"
}
layer {
  name: "drop7"
  type: "Dropout"
  bottom: "fc7"
  top: "fc7"
  dropout_param {
    dropout_ratio: 0.5
  }
}
layer {
  name: "fc8"
  type: "InnerProduct"
  bottom: "fc7"
  top: "fc8"
  inner_product_param {
    num_output: 1000
  }
}
layer {
  name: "prob"
  type: "Softmax"
  bottom: "fc8"
  top: "prob"
}

浅谈caffe中train_val.prototxt和deploy.prototxt文件的区别相关推荐

  1. 浅谈Java中的Set、List、Map的区别

    就学习经验,浅谈Java中的Set,List,Map的区别,对JAVA的集合的理解是想对于数组: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),JAVA集合可以存储和操 ...

  2. Java基础学习总结(29)——浅谈Java中的Set、List、Map的区别

    Java中的Set,List,Map的区别,对JAVA的集合的理解是相对于数组: 数组是大小固定的,并且同一个数组只能存放类型一样的数据(基本类型/引用类型),JAVA集合可以存储和操作数目不固定的一 ...

  3. 浅谈Python中的type()、dtype()、astype()的区别

    函数 说明 type() 返回数据结构类型(list.dict.numpy.ndarray 等) dtype() 返回数据元素的数据类型(int.float等)备注:1.由于 list.dict 等可 ...

  4. 浅谈PHP中静态方法调用和实例化类调用的区别

    1.观点一: 静态方法只有一个,无论你调用多少次,都是共用的,是没有对象的概念,因此不能在静态方法里面使用$this调用,如果非得调用的话,只能实例化自身类 实例化不一样,每一个实例化是一个对象,拥有 ...

  5. 浅谈linux中的硬链接和软链接文件以及ln的使用方法

    在linux系统中有一种文件叫做链接文件,可以为解决文件的共享使用.链接的方式可以分为两种,一种是硬链接(Hard Link),另一种是软链接或者也称为符号链接(Symbolic Link). 一.基 ...

  6. 浅谈JSP中include指令与include动作标识的区别

    JSP中主要包含三大指令,分别是page,include,taglib.本篇主要提及include指令. include指令使用格式:<%@ include file="文件的绝对路径 ...

  7. java 中的单元测试_浅谈Java 中的单元测试

    单元测试编写 Junit 单元测试框架 对于Java语言而言,其单元测试框架,有Junit和TestNG这两种, 下面是一个典型的JUnit测试类的结构 package com.example.dem ...

  8. mybatis与php,浅谈mybatis中的#和$的区别

    浅谈mybatis中的#和$的区别 发布于 2016-07-30 11:14:47 | 236 次阅读 | 评论: 0 | 来源: 网友投递 MyBatis 基于Java的持久层框架MyBatis 本 ...

  9. 浅谈CSS3中display属性的Flex布局,关于登陆页面属性框的设置

    声明:本文转发自三里屯柯南的浅谈CSS3中display属性的Flex布局http://www.cnblogs.com/xuyuntao/articles/6391728.html 基本概念 采用Fl ...

最新文章

  1. java iris_利用K-Means聚类算法实现对iris.data.ulab
  2. 090_HTMLCollection和NodeList对象
  3. Caffe实战二(手写体识别例程:CPU、GPU、cuDNN速度对比)
  4. Eclipse VIM
  5. 【控制】《自动控制原理》胡寿松老师-第2章-控制系统的数学模型
  6. 直播回顾丨拆解 LTV:增长焦虑,企业如何诊断黄金流量?
  7. 这段iframe代码可以盖住dropdownlist
  8. 人人网登陆(selenium、PtantomJS结合)
  9. 12V转3.3V稳压芯片
  10. Android多媒体详解
  11. 手机qq邮箱html,手机QQ邮箱在哪里找
  12. 配置失败还原请勿关闭计算机怎么办,win7系统出现“配置windows update失败 还原更改 请勿关闭计算机”,长时间没反应,无法进入系统的解决方案...
  13. vue 根据权限显示不同页面解决方案
  14. 工厂如何选择一款合适的工业平板电脑?
  15. poco mysql 库_Poco Mysql使用
  16. 安卓开发仿微信图片拖拽_仿微信朋友圈发表图片拖拽和删除功能
  17. 元宇宙iwemeta:红杉资本 all in 区块链?
  18. NK/DC细胞膜仿生脂质体药物载体|真核细胞膜包覆仿生纳米粒|肿瘤细胞膜包裹的仿生纳米颗粒
  19. 关于nbsp的一点笔记
  20. 港澳四晚五日游(购物团)游记

热门文章

  1. 天津工业大学19年计算机考研大纲,2019年天津工业大学《计算机原理及接口技术》考研复试大纲...
  2. datagrid出现相同两组数据_stata 数据操作基础知识:以一篇论文数据操作为例
  3. MVC模型构建管理系统
  4. EventBus3.0 List事件遇到的坑
  5. Linux>软链接的作用与使用
  6. 121. Leetcode 5. 最长回文子串 (动态规划-子序列问题)
  7. 单链表中删除指定值的节点
  8. NTU 课程笔记:MAS 714(16) 图灵机
  9. AB测试:基础概念、应用场景及入门指南
  10. MATLAB实战系列(二十六)-matlab通过遗传算法求解车间调度问题