caffe中在proto文件里定义网络各层结构

来源:互联网 发布:apache cgi 配置 编辑:程序博客网 时间:2024/06/06 14:12

caffe中,网络结构是神经网络建模和计算的基本单元。而不同类型的层需要有不同的配置,因此对caffe中各个类型的层结构做一个总结。

  • 网络训练和测试层
layer{  name:"data"  type: "HDF5Data"  top: "data"  top: "label"  include {    phase: TRAIN  }  hdf5_data_param {   source: "examples/model1/indian_pines_train.txt"    batch_size: 32    shuffle: true  }}layer {  name: "data"  type: "HDF5Data"  top: "data"  top: "label"  include {    phase: TEST  }  hdf5_data_param {    source: "examples/model1/indian_pines_test.txt"    batch_size: 6904  }}

其中type中需要说明训练和测试的数据类型,sorce说明数据的来源。batch_size为一次性输入的数据量。

  • 卷积层(Convolution)
layer {  name: "conv1"  type: "Convolution"  bottom: "data"  top: "conv1"  param {    lr_mult: 1  }  param {    lr_mult: 2  }  convolution_param {    num_output: 20    kernel_size: 5    stride: 1    weight_filler {      type: "xavier"    }    bias_filler {      type: "constant"    }  }}

类型:Convolution。
num_output: 滤波器的数量。
kernel_size:每个滤波器的高度和宽度。
stride: 输入滤波器的间隔。
weight_filler:滤波器的初始分布和分布参数。
bias_filler:默认type:constant,value:0

  • 池化层(Pooling)
layer {  name: "pool1"  type: "Pooling"  bottom: "conv1"  top: "pool1"  pooling_param {    pool: MAX    kernel_size: 2    stride: 2  }}

类型:Pooling
作用:合并相似的特征。
kernel_size:说明每个滤波器的宽度和高度。
pool:池化方法,有MAX,AVE,STOCHASTIC
stride:说明输入滤波器的间隔。

  • 全连接层(Inner Product)
layer {  name: "ip1"  type: "InnerProduct"  bottom: "pool2"  top: "ip1"  param {    lr_mult: 1  }  param {    lr_mult: 2  }  inner_product_param {    num_output: 500    weight_filler {      type: "xavier"    }    bias_filler {      type: "constant"    }  }}

类型:InnerProduct
作用:将输入的数据以简单的向量形式进行处理,并且输出一个简单的向量。

  • 激励层
    1.ReLU
layer {  name: "relu1"  type: "ReLU"  bottom: "ip1"  top: "ip1"}

类型:ReLU
为层内运算的一个层
可选参数negative_slope :[默认:0]指定如何去除负值。通过乘以一个斜率值(1)还是设置负数值为0(0)。

对于给定的一个输入值x,如果x > 0,ReLU层的输出为x,如果x < 0,ReLU层的输出为negative_slope * x。如果negative_slope参数没有设置,它就等价于标准ReLU函数:max(x,0)。它也支持原地计算,这意味着底层blob和顶层blob可以相同,以减少资源消耗。

2.Sigmoid

layer {  name: "encode1neuron"  bottom: "encode1"  top: "encode1neuron"  type: "Sigmoid"}

Sigmoid层对每个输入元素x计算其sigmoid(x)值作为输出。

  • Concatenation
layer{   name:"out2"   type:"Concat"   bottom: "Wrand1"   bottom:"Wrand2"   bottom:"W3"   top:"out2"   concat_param {    axis: 1  }}

Concat层将串连多个输入blob,成为一个单一的输出blob。

  • Dropout
layer{   name:"drop3"   type:"Dropout"   bottom:"U3"   top:"U3"   dropout_param{   dropout_ratio:0.1  }}

在Dropout层中,momentum一般要设置为095-0.99之间,需要设置更高的学习速率,网络的训练时间会更长。

  • BatchNormalization
 layer{   name:"bn2"   type:"BatchNorm"   bottom:"out2"   top:"bn2"}
  • Accuracy
layer {  name: "accuracy"  type: "Accuracy"  bottom: "Y"  bottom:"label"  top: "accuracy"  include {    phase: TEST  }}
  • Softmax
layer {  name: "loss"  type: "SoftmaxWithLoss"  bottom: "Y"  bottom:"label"  top: "loss"}

我目前就接触到了这么多的层,算是比较入门级的了,其它更深的理解和层后面再补充。
参考博文
这里写链接内容

0 0
原创粉丝点击