Caffe 初学拾遗(十一) Layer Catalogue (Common Layer)

17 篇文章 0 订阅

{承接CNN学习入门,笔者在这里对Caffe官方网站上的相关介绍进行了翻译总结,欢迎大家交流指正}

本文基于此刻最新的release,Caffe-rc3


5. Common Layer:

Inner Product:

1.网络类型:InnerProduct

2.CPU版本实现:./src/caffe/layers/inner_product_layer.cpp

3.GPU版本实现:./src/caffe/layers/inner_product_layer.cu

4.参数(InnerProductParameter inner_product_param):

4.1 Required:

4.1.1 num_output(c_o):filters的数目或者说是卷积kernel的数目

4.2 Strongly Recommended

4.2.1 weight_filler[default type:'constant' value 0]

4.3 Optional

4.3.1 bias_filler[default type: 'constant' value: 0]

4.3.2 bias_term[default true]:是否添加bias项在filter输出之后 Wx + bias

5.输入:n * c_i * h_i * w_i

6.输出:n * c_o * 1 * 1 

7.示例:

layer {
  name: "fc8"
  type: "InnerProduct"
  # learning rate and decay multipliers for the weights
  param { lr_mult: 1 decay_mult: 1 }
  # learning rate and decay multipliers for the biases
  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
    }
  }
  bottom: "fc7"
  top: "fc8"
}
InnerProductLayer也被称为全连接层,将input视为一个向量,产生一个向量形式的输出,blob的height与width都被设定为1。


Splitting:

Split layer将input的blob切分到多个输出blob上,这在一个blob需要输出到多个output layer时是很有用的。


Flattening:

Flatten layer将input的shape为n * c * h * w 平整到output的shape为 n *(c*h*w)


Reshape:

1.网络类型:Reshape

2.实现:./src/caffe/layers/reshape_layer.cpp

3.参数(ReshapeParameter reshape_param):

3.1 Optional

3.1.1 shape

4.输入:一个任意维度的blob。

5.输出:相同的blob,但是维度变为reshape_param所定义的。

6.示例:

 layer {
    name: "reshape"
    type: "Reshape"
    bottom: "input"
    top: "output"
    reshape_param {
      shape {
        dim: 0  # copy the dimension from below
        dim: 2
        dim: 3
        dim: -1 # infer it from the other dimensions
      }
    }
  }
Reshape Layer可以被用来改变input的维度,而不改变其中的数据。

就像Flatten layer的操作一样,只要有维度被改变,数据在操作中没有被拷贝。


Output的维度在ReshapeParam proto中被指定,正整数将直接指定OUTPUT的对应维度。

此外,两个特殊值也可以被指定为目标维度值。

0:意味着“拷贝来自bottom layer的对应维度值”。也就说,如果bottom在其第一维,维度值是2,那么top的第一维的维度也是2。

-1:意味着“从其他维度推测该维的维度”。类似于numpy中的-1,或者matlab中的[]在reshape操作中的意思。该维的维度值将会通过元素总数保持不变的特性而被计算出来。但是-1最多只能被使用一次,否则维度将无法确定。


在另一个例子中,reshape_param{ shape { dim: 0 dim: -1} }与Flatten Layer执行完全相同的操作。


Concatenation:

1.网络类型:Concat

2.CPU版本实现:./src/caffe/layers/concat_layer.cpp

3.GPU版本实现:./src/caffe/layers/concat_layer.cu

4.参数(ConcatParameter concat_param):

4.1 Optional

4.1.1 axis[default 1]: 0 为在num上扩增 1 为在channel上扩增

5.输入:n_i * c_i * h * w 每一个blob for i = 1:K

6.输出:

if axis = 0:

(n_1 + n_2 + ... + n_K) * c_1 * h * w 所有的input的c_i应该是一致的。

if axis = 1:

n_1 * (c_1 + c_2 + ... + c_K) * h * w 所有的input的n_i应该是一致的。

7.示例:

layer {
  name: "concat"
  bottom: "in1"
  bottom: "in2"
  top: "out"
  type: "Concat"
  concat_param {
    axis: 1
  }
}
Concat Layer意在将多个input blob串接为一个output blob。


Slicing:

Slice Layer将一个input Layer按照给定的维度在给定的index处进行切分。

E.g.

layer {
  name: "slicer_label"
  type: "Slice"
  bottom: "label"
  ## Example of label with a shape N x 3 x 1 x 1
  top: "label1"
  top: "label2"
  top: "label3"
  slice_param {
    axis: 1
    slice_point: 1
    slice_point: 2
  }
}
axis:指定了目标维。slice_point:指明了在被选中维度中的index(index的数目必须与top blob的数目减去一后一致)。


Elementwise Operations
Eltwise


Argmax
ArgMax

Softmax
Softmax

Mean-Variance Normalization
MVN



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值