caffe的model是须要用prototxt来定义的,若是要训练本身的model咱们就须要本身来写prototxt文件,这篇博文主要写caffe的layer是如何来定义的。html
参考:http://caffe.berkeleyvision.org/tutorial/layers.htmlapp
layer的源代码在$caffe-master/src/caffe/layerside
Convolution
ConvolutionParameter convolution_param
)
num_output
(c_o
):filter的的数目 kernel_size
(or kernel_h
and kernel_w
):filter的尺寸,即长、宽weight_filler
:对权值的初始化设置,默认是{type:"constant" value:0},即初始化为常数0。type也能够选择高斯分布,这须要给定标准差和均值 bias_term
[default true
]:是否对filter设定偏置项,默认为true pad
(or pad_h
and pad_w
) [default 0]:对输入的每一个边进行填充像素的个数,默认为0stride
(or stride_h
and stride_w
) [default 1]:filter在输入图像上的滑动步长group
(g) [default 1]:当g>1时,将输入和输出的channels分为g个组,第i个输入group channels只与第i个输出group channels相对应。 n * c_i * h_i * w_i
学习
n * c_o * h_o * w_o
,其中h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1
,w_o也相似spa
layer {
name: "conv1" //层的名字
type: "Convolution" //层的类型
bottom: "data" //底层的blob
top: "conv1" //上层的blob
//filters的学习率和衰减参数
param { lr_mult: 1 decay_mult: 1 }
// biases的学习率和衰减参数
param { lr_mult: 2 decay_mult: 0 }
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" // 用Gaussian分布初始化
std: 0.01 // 标准差为0.01,均值默认为0
}
bias_filler {
type: "constant" //初始化为常数
value: 0
}
}
}
Pooling
PoolingParameter pooling_param
kernel_size
:filter的尺寸pool
[default MAX]:pool的类型,MAX、AVE或者 STOCHASTIC pad
(or pad_h
and pad_w
) [default 0]:对输入的每一个边进行填充像素的个数,默认为0 stride
(or stride_h
and stride_w
) [default 1]:filter在输入图像上的滑动步长 n * c_i * h_i * w_i
code
n * c_o * h_o * w_o
,其中h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1
,w_o也相似htm
layer {
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
}
}
layer {
name: "relu1"
type: "ReLU"
bottom: "conv1"
top: "conv1"
}
layer {
name: "drop7"
type: "Dropout"
bottom: "fc7"
top: "fc7"
dropout_param {
dropout_ratio: 0.5 //dropout率
}
}
Pooling
InnerProductParameter inner_product_param
kernel_size
:filter的尺寸weight_filler
:对权值的初始化设置,默认是{type:"constant" value:0},即初始化为常数0。type也能够选择高斯分布,这须要给定标准差和均值bias_term
[default true
]:是否对filter设定偏置项,默认为truebias_filler
[default type: 'constant' value: 0
] n * c_i * h_i * w_i
blog
n * c_o * h_o * w_o
,其中h_o = (h_i + 2 * pad_h - kernel_h) / stride_h + 1
,w_o也相似get
layer {
name: "fc8"
type: "InnerProduct"
param { lr_mult: 1 decay_mult: 1 }
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"
}
layer {
name: "loss"
type: "SoftmaxWithLoss"
bottom: "fc8"
bottom: "label"
top: "loss"
}
layer {
name: "accuracy"
type: "Accuracy"
bottom: "fc8"
bottom: "label"
top: "accuracy"
include {
phase: TEST
}
}