Caffe学习笔记3-Layer的相关学习
2015-08-13 16:08
387 查看
Caffe学习笔记3-Layer的相关学习
ByYuFeiGan
2014-12-09 更新日期:2014-12-10
文章目錄
1.
Layer
1.1.
data_layer
1.1.1.
DATA
1.1.2.
MEMORY_DATA
1.1.3.
HDF5_DATA
1.1.4.
HDF5_OUTPUT
1.1.5.
IMAGE_DATA
1.2.
neuron_layer
1.3.
loss_layer
1.4.
common_layer
1.4.1.
InnerProductLayer
1.4.2.
SplitLayer
1.4.3.
FlattenLayer
1.4.4.
ConcatLayer
1.4.5.
SilenceLayer
1.4.6.
(Elementwise Operations)
1.5.
vision_layer
1.5.1.
ConvolutionLayer
1.5.2.
Im2colLayer
1.5.3.
LRNLayer
1.5.4.
PoolingLayer
Layer
Layer是所有层的基类,在Layer的基础上衍生出来的有5种Layers:data_layer
neuron_layer
loss_layer
common_layer
vision_layer
它们都有对应的[.hpp .cpp]文件声明和实现了各个类的接口。下面一个一个地讲这5个Layer。
data_layer
先看data_layer.hpp中头文件调用情况:1 2 3 4 5 6 7 8 9 10 11 12 | #include "boost/scoped_ptr.hpp" #include "hdf5.h" #include "leveldb/db.h" #include "lmdb.h" //前4个都是数据格式有关的文件 #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/data_transformer.hpp" #include "caffe/filler.hpp" #include "caffe/internal_thread.hpp" #include "caffe/layer.hpp" #include "caffe/proto/caffe.pb.h" |
DATA
MEMORY_DATA
HDF5_DATA
HDF5_OUTPUT

IMAGE_DATA
其实还有两种
WINDOW_DATA,
DUMMY_DATA用于测试和预留的接口,这里暂时不管。
DATA
1 2 3 4 5 6 | template <typename Dtype> class BaseDataLayer : public Layer<Dtype> template <typename Dtype> class BasePrefetchingDataLayer : public BaseDataLayer<Dtype>, public InternalThread template <typename Dtype> class DataLayer : public BasePrefetchingDataLayer<Dtype> |
source,
batch_size, (
rand_skip), (
backend)。后两个是可选。
MEMORY_DATA
1 2 | template <typename Dtype> class MemoryDataLayer : public BaseDataLayer<Dtype> |
MemoryDataLayer::Reset,输入参数有
batch_size,
channels,
height,
width。
HDF5_DATA
1 2 | template <typename Dtype> class HDF5DataLayer : public Layer<Dtype> |
source,
batch_size。
HDF5_OUTPUT
1 2 | template <typename Dtype> class HDF5OutputLayer : public Layer<Dtype> |
file_name。
IMAGE_DATA
1 2 | template <typename Dtype> class ImageDataLayer : public BasePrefetchingDataLayer<Dtype> |
source,
batch_size, (
rand_skip), (
shuffle), (
new_height), (
new_width)。
neuron_layer
先看neuron_layer.hpp中头文件调用情况1 23 | #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/layer.hpp" #include "caffe/proto/caffe.pb.h" |
bottom,
topsize。
Caffe中实现了大量激活函数GPU和CPU的都有很多。它们的父类都是
NeuronLayer
1 2 | template <typename Dtype> class NeuronLayer : public Layer<Dtype> |
1 2 3 4 5 6 | layers { name: "relu1" type: RELU  bottom: "conv1"  top: "conv1" } |
loss_layer
Loss层计算网络误差,loss_layer.hpp头文件调用情况:1 23 | #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/layer.hpp" #include "caffe/neuron_layers.hpp" #include "caffe/proto/caffe.pb.h" |
neuron_layers.hpp,估计是需要调用里面的函数计算Loss,一般来说Loss放在最后一层。caffe实现了大量loss function,它们的父类都是
LossLayer。
1 2 | template <typename Dtype> class LossLayer : public Layer<Dtype> |
common_layer
先看common_layer.hpp头文件调用:1 2 3 4 5 67 | #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/data_layers.hpp" #include "caffe/layer.hpp" #include "caffe/loss_layers.hpp" #include "caffe/neuron_layers.hpp" #include "caffe/proto/caffe.pb.h" |
data_layers.hpp,
loss_layers.hpp,
neuron_layers.hpp说明这一层肯定开始有复杂的操作了。
这一层主要进行的是
vision_layer的连接
声明了9个类型的common_layer,部分有GPU实现:
InnerProductLayer
SplitLayer
FlattenLayer
ConcatLayer
SilenceLayer
(Elementwise Operations) 这里面是我们常说的激活函数层Activation Layers。
EltwiseLayer
SoftmaxLayer
ArgMaxLayer
MVNLayer
InnerProductLayer
常常用来作为全连接层,设置格式为:1 2 3 4 5 6 7 8 9 10 11 1213 | layers { name: "fc8" type: INNER_PRODUCT  blobs_lr: 1 # learning rate multiplier for the filters  blobs_lr: 2 # learning rate multiplier for the biases  weight_decay: 1 # weight decay mu weight_decay: 0 # weight decay multiplier for the biases inner_product_param { num_output: 1000  weight_filler {  type: "gaussian"  std: 0.01  }  bias_filler {  type: "constant"  value: 0  } } bottom: "fc7"  top: "fc8 } |
SplitLayer
用于一输入对多输出的场合(对blob)FlattenLayer
将n * c * h * w变成向量的格式n * ( c * h * w ) * 1 * 1ConcatLayer
用于多输入一输出的场合。1 2 3 4 5 67 | layers { name: "concat" bottom: "in1" bottom: "in2" top: "out" type: CONCAT concat_param {  concat_dim: 1 } } |
SilenceLayer
用于一输入对多输出的场合(对layer)(Elementwise Operations)
EltwiseLayer,
SoftmaxLayer,
ArgMaxLayer,
MVNLayer
vision_layer
头文件包含前面所有文件,也就是说包含了最复杂的操作。1 2 3 4 5 67 | #include "caffe/blob.hpp" #include "caffe/common.hpp" #include "caffe/common_layers.hpp" #include "caffe/data_layers.hpp" #include "caffe/layer.hpp" #include "caffe/loss_layers.hpp" #include "caffe/neuron_layers.hpp" #include "caffe/proto/caffe.pb.h" |
1 2 3 4 5 67 | template <typename Dtype> class ConvolutionLayer : public Layer<Dtype> template <typename Dtype> class Im2colLayer : public Layer<Dtype> template <typename Dtype> class LRNLayer : public Layer<Dtype> template <typename Dtype> class PoolingLayer : public Layer<Dtype> |
ConvolutionLayer
最常用的卷积操作,设置格式如下1 2 3 4 5 6 7 8 9 10 11 1213 | layers { name: "conv1"  type: CONVOLUTION  bottom: "data"  top: "conv1"  blobs_lr: 1 # learning rate multiplier for the filters  blobs_lr: 2 # learning rate multiplier for the biases  weight_decay: 1 # weight decay multiplier for the filters  weight_decay: 0 # weight decay multiplier for the biases convolution_param {  num_output: 96 # learn 96 filters  kernel_size: 11 # each filter is 11x11  stride: 4 # step 4 pixels between each filter application weight_filler {  type: "gaussian" # initialize the filters from a Gaussian std: 0.01 # distribution with stdev 0.01 (default mean: 0) }  bias_filler {  type: "constant" # initialize the biases to zero (0)  value: 0 } } } |
Im2colLayer
与MATLAB里面的im2col类似,即image-to-column transformation,转换后方便卷积计算LRNLayer
全称local response normalization layer,在Hinton论文中有详细介绍ImageNet Classification with Deep Convolutional Neural Networks。PoolingLayer
即Pooling操作,格式:1 2 3 4 5 67 | layers { name: "pool1" type: POOLING bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 3 # pool over a 3x3 region stride: 2 # step two pixels (in the bottom blob) between pooling regions } } |
相关文章推荐
- JS 前端框架 AngularJS 国际化
- 剑指offer第40题 数组中只出现一次的数字
- js实现仿网易点击弹出提示同时背景变暗效果
- 解析json字符串:eval
- Caffe学习笔记2-Caffe的三级结构(Blobs,Layers,Nets)
- jquery中子元素和后代元素的区别
- nodejs co 本质学习 及演进代码
- My97DatePicker设置开始时间与结束时间控制以及js中时间的比较
- Caffe学习笔记1-安装以及代码结构
- 用js写一个实现map
- jquery each报 Uncaught TypeError: Cannot use 'in' operator to search for错误
- js正则表达式
- UVA 10795 A Different Task
- 时隔8年HTML 5终于定稿!
- javaScript中的提示对话框
- js中typeof的用法汇总
- visual studio 2005提示脚本错误 /VC/VCWizards/2052/Common.js
- JS - IE or not:判断是否为IE浏览器方法
- bootstrap 主题颜色搭配
- javascript 函数学习