深度学习中Concat层和Flatten层作用

一些其它层的作用参考:

Keras各种layer的作用及用法--简要总结:https://www.jianshu.com/p/86d667ee3c62

Concat层

  • Layer type: Concat
  • 头文件位置: ./include/caffe/layers/concat_layer.hpp
  • CPU 执行源文件位置:./src/caffe/layers/concat_layer.cpp
  • CUDA GPU 执行源文件位置: ./src/caffe/layers/concat_layer.cu

      Concat层的功能:Concat层实现输入数据的拼接。Concat层是一个实用程序层,它将多个输入blob连接到一个输出blob(按照给定的axis,注意除了规定的axis以外,被concat的输入bolb的其他维度的size必须一致)。

参数定义:

参数(ConcatParameter concat_param) 
定义位置: ./src/caffe/proto/caffe.proto

message ConcatParameter {
  // The axis along which to concatenate -- may be negative to index from the
  // end (e.g., -1 for the last axis).  Other axes must have the
  // same dimension for all the bottom blobs.
  // By default, ConcatLayer concatenates blobs along the "channels" axis (1).
  // 指定拼接的维度,默认为1即以channel通道进行拼接;支持负索引,即-1表示最后一个维度
  optional int32 axis = 2 [default = 1];

  // DEPRECATED: alias for "axis" -- does not support negative indexing.
  // 以后会被弃用,作用同axis一样,但不能指定为负数
  optional uint32 concat_dim = 1 [default = 1];
}

      caffe中数据通常为4个维度,即 num×channels×height×width,因此默认值1表示channels通道进行拼接。而0表示num这个维度,即数量上的叠加。

使用方法:

layer {
  name: "data_all"
  type: "Concat"
  bottom: "data_classfier"
  bottom: "data_boundingbox"
  bottom: "data_facialpoints"
  top: "data_all"
  concat_param {
    axis: 0
  }
}

     除了拼接维度外的其它维度都必须相等。比如上面,输入图像均为 24×24×3,用于分类的有150张图片,用于boundingbox回归的有50张,用于关键点回归的也有50张,则最后拼接的结果就是(150+50+50)×3×24×24

Flatten层

作用:Flatten层用来将输入“压平”,即把多维的输入一维化,常用在从卷积层到全连接层的过渡。Flatten不影响batch的大小。

为了更好的理解Flatten层作用,我把这个神经网络进行可视化如下图:

Caption

猜你喜欢

转载自blog.csdn.net/ytusdc/article/details/86610897