caffe中常见层的用法以及参数

caffe中常见的一些层的用法,和参数配置
官方文档 http://caffe.berkeleyvision.org/tutorial/layers.html
1.Reshape 改变输入数据的维度
常见配置如下:

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
      }
    }
  }

输入和输出都是类似blob的四维张量,N*C*W*H
通过reshape_param中的shape参数改变张量的维度四个dim分别代表output(top)中的数据维度,后面的数字表示给维度具体要变成什么样。
举个例子,设输入为 32*3*28*28
shape {
dim: 0 # copy the dimension from below
dim: 0
dim: 14
dim: -1 # infer it from the other dimensions
}
dim:0 表示 output(top)中的N 直接复制 input(bottom)中N的维度 为 32
dim:0表示 output(top)中的直接复制 input(bottom)中C的维度 为3
dim:3表示 output(top)中的W 变为28维 变为 14
dim:-1 表示这一维度的具体数字通过其他维度推算 为56,推算过程如下:总的数据量不变,只改变 NCWH 四个维度的具体数字
(32*3*28*28)/(32*3*14) = 56
因此,经过Reshape后输出为32*3*14*56

2.Flatten变多维矩阵为一维向量
常见配置如下:

layer {
  name: "rpn_cls_score_flat"
  type: "Flatten"
  bottom: "rpn_cls_score_perm"
  top: "rpn_cls_score_flat"
  flatten_param {
    axis: 1
  }
}

Flatten层是把一个输入的大小为n * c * h * w变成一个简单的向量,其大小为 n * (c*h*w) * 1 * 1
axis [default 1]:0代表链接N,1代表链接C
3.Concat按照axis连接多个blob
常见配置如下:

layer {
  name: "concat"
  bottom: "in1"
  bottom: "in2"
  top: "out"
  type: "Concat"
  concat_param {
    axis: 1
  }
}

输入输出均为N*C*W*H的blob张量
可选参数:
axis [default 1]:0代表链接N,1代表链接C
通过全连接层后的大小变化:
输入:从1到K的每一个blob的大小:ni×ci×h×w
输出:
如果axis = 0: (n1+n2+…+nK)×c1×h×w,需要保证所有输入的ci相同。
如果axis = 1: n1×(c1+c2+…+cK)×h×w,需要保证所有输入的n_i 相同。
通过Concatenation层,可以把多个的blobs链接成一个blob。

4.Transpose
5.Permute
6.Im2col
参考博客


版权声明:本文为u014553172原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。