Caffe文件详解

对caffe的超参数文件 ***solver.prototxt 和网络结构文件 ***_train_test.prototxt 进行详解。

超参文件详解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#网络模型描述文件
#也可以用train_net和test_net来对训练模型和测试模型分别设定
#train_net: "xxxxxxxxxx"
#test_net: "xxxxxxxxxx"
net: "E:/Caffe-windows/caffe-windows/examples/mnist/lenet_train_test.prototxt"
#这个参数要跟test_layer结合起来考虑,在test_layer中一个batch是100,而总共的测试图片是10000张
#所以这个参数就是10000/100=100
test_iter: 100
#每训练500次进行一次测试
test_interval: 500
#学习率
base_lr: 0.01
#动力
momentum: 0.9
#type:SGD #优化算法的选择。这一行可以省略,因为默认值就是SGD,Caffe中一共有6中优化算法可以选择
#Stochastic Gradient Descent (type: "SGD"), 在Caffe中SGD其实应该是Momentum
#AdaDelta (type: "AdaDelta"),
#Adaptive Gradient (type: "AdaGrad"),
#Adam (type: "Adam"),
#Nesterov’s Accelerated Gradient (type: "Nesterov")
#RMSprop (type: "RMSProp")
#权重衰减项,其实也就是正则化项。作用是防止过拟合
weight_decay: 0.0005
#学习率调整策略
#如果设置为inv,还需要设置一个power, 返回base_lr * (1 + gamma * iter) ^ (- power),其中iter表示当前的迭代次数
lr_policy: "inv"
gamma: 0.0001
power: 0.75
#每训练100次屏幕上显示一次,如果设置为0则不显示
display: 100
#最大迭代次数
max_iter: 2000
#快照。可以把训练的model和solver的状态进行保存。每迭代5000次保存一次,如果设置为0则不保存
snapshot: 5000
snapshot_prefix: "E:/Caffe-windows/caffe-windows/examples/mnist/models"
#选择运行模式
solver_mode: GPU

网络结构文件详解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
name: "LeNet"               #网络的名字"LeNet"
layer { #定义一个层
name: "mnist" #层的名字"mnist"
type: "Data" #层的类型"Data",表明数据来源于LevelDB或LMDB。另外数据的来源还可能是来自内存,HDF5,图片等
top: "data" #输出data
top: "label" #输出label
include {
phase: TRAIN #该层只在TRAIN训练的时候有效
}
transform_param { #数据的预处理
scale: 0.00390625 #1/256,将输入的数据0-255归一化到0-1之间
}
data_param {
source: "E:/Caffe-windows/caffe-windows/examples/mnist/lmdb/train_lmdb" #数据来源
batch_size: 64 #每个批次处理64张图片
backend: LMDB #数据格式LMDB
}
}
layer { #定义一个层
name: "mnist" #层的名字"mnist"
type: "Data" #层的类型"Data",表明数据来源于LevelDB或LMDB
top: "data" #输出dada
top: "label" #输出label
include {
phase: TEST #该层只在TEST测试的时候有效
}
transform_param { #数据的预处理
scale: 0.00390625 #1/256,将输入的数据0-255归一化到0-1之间
}
data_param {
source: "E:/Caffe-windows/caffe-windows/examples/mnist/lmdb/test_lmdb" #数据来源
batch_size: 100 #每个批次处理100张图片
backend: LMDB #数据格式LMDB
}
}
layer { #定义一个层
name: "conv1" #层的名字"conv1"
type: "Convolution" #层的类型"Convolution"
bottom: "data" #输入data
top: "conv1" #输出conv1
param { #这个是权值的学习率
lr_mult: 1 #学习率系数。最终的学习率是这个学习率系数lr_mult乘以solver.prototxt里面的base_lr
}
param { #这个是偏置的学习率
lr_mult: 2 #学习率系数。最终的学习率是这个学习率系数lr_mult乘以solver.prototxt里面的base_lr
}
convolution_param {
num_output: 20 #卷积核的个数为20,或者表示输出特征平面的个数为20
kernel_size: 5 #卷积核的大小5*5。如果卷积核长和宽不等,则需要用kernel_h和kernel_w分别设置
stride: 1 #步长为1。也可以用stride_h和stride_w来设置
weight_filler { #权值初始化
type: "xavier" #使用"Xavier"算法,也可以设置为"gaussian"
}
bias_filler { #偏置初始化
type: "constant" #一般设置为"constant",取值为0
}
}
}
layer { #定义一个层
name: "pool1" #层的名字"pool1"
type: "Pooling" #层的类型"Pooling"
bottom: "conv1" #输入conv1
top: "pool1" #输出pool1
pooling_param {
pool: MAX #池化方法。常用的方法有MAX,AVE或STOCHASTIC
kernel_size: 2 #池化核的大小2*2。如果池化核长和宽不等,则需要用kernel_h和kernel_w分别设置
stride: 2 #池化的步长。也可以用stride_h和stride_w来设置
}
}
layer {
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 50 #卷积核的个数为50,或者表示输出特征平面的个数为50
kernel_size: 5
stride: 1
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer {
name: "pool2"
type: "Pooling"
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 2
stride: 2
}
}
layer { #定义一个层
name: "ip1" #层的名字"ip1"
type: "InnerProduct" #层的类型"InnerProduct",全连接层
bottom: "pool2" #输入pool2
top: "ip1" #输出ip1
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500 #500个神经元
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer { #定义一个层
name: "relu1" #层的名字"relu1"
type: "ReLU" #层的类型"ReLU",激活函数
bottom: "ip1" #输入ip1
top: "ip1" #输出ip1
}
layer { #定义一个层
name: "ip2" #层的名字"ip2"
type: "InnerProduct" #层的类型"InnerProduct",全连接层
bottom: "ip1" #输入ip1
top: "ip2" #输出ip2
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 10 #10个输出,代表10个分类
weight_filler {
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer { #定义一个层
name: "accuracy" #层的名字"accuracy"
type: "Accuracy" #层的类型"Accuracy",用来判断准确率
bottom: "ip2" #层的输入ip2
bottom: "label" #层的输入label
top: "accuracy" #层的输出accuracy
include {
phase: TEST #该层只在TEST测试的时候有效
}
}
layer { #定义一个层
name: "loss" #层的名字"loss"
type: "SoftmaxWithLoss" #层的类型"SoftmaxWithLoss",输出loss值
bottom: "ip2" #层的输入ip2
bottom: "label" #层的输入label
top: "loss" #层的输出loss
}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!