上一篇博客介绍了如何修改网络结构,修改网络结构的前提是要知道模型的参数都是干什么的,所以想来先去,觉得还是补充一个博客把网络协议的参数做一个简单的说明(还是以LeNet为例子,这个例子太经典了):
name: "LeNet" #网络名称
layer { #定义一个层
name: "mnist" #层的名称
type: "Data" #层类型
top: "data" #输出,有两个,data和label
top: "label"
data_param {
source: "examples/mnist/mnist-train-leveldb" #训练数据所在位置
backend: LEVELDB #数据类型
batch_size: 64 #批量数目,表示一次读取64张图
}
transform_param {
scale: 0.00390625 #数据变换使用数据缩放因子
}
include: { phase: TRAIN } #该层只在训练阶段有效
}
layer { #同上
name: "mnist"
type: "Data"
top: "data"
top: "label"
data_param {
source: "examples/mnist/mnist-test-leveldb" #测试数据路径
backend: LEVELDB #测试数据类型
batch_size: 100 #一次读入100张测试数据
}
transform_param {
scale: 0.00390625 #测试数据尺度变换
}
include: { phase: TEST } #该层只在测试阶段有效,既分类阶段有效
}
layer { #定义一个卷积层
name: "conv1"
type: "Convolution" #类型决定了层的类型
bottom: "data" #该层的输入层
top: "conv1" #该层的输出层
param {
lr_mult: 1 #权值学习速率倍乘因子,1倍表示保持与全局参数一致
}
param {
lr_mult: 2 #偏置学习速率倍乘因子,是全局参数的2倍
}
convolution_param { #卷积参数
num_output: 20 #feature map大小,既特征图个数为20
kernel_size: 5 #卷积核大小
stride: 1 #卷积输出跳跃间隔,1,表示无跳跃
weight_filler { #权值使用xavier填充器
type: "xavier"
}
bias_filler { #偏置使用常数填充器,默认为0
type: "constant"
}
}
}
layer { #定义池化层
name: "pool1"
type: "Pooling" #类型
bottom: "conv1" #采样层输入
top: "pool1" #采样层输出
pooling_param { #池化参数
pool: MAX #max池化
kernel_size: 2 #采样窗口大小2*2
stride: 2 #采样窗口输出跳跃间隔2*2
}
}
layer { #非线性层,Insanity方法
name: "Insanity1"
type: "Insanity"
bottom: "pool1"
top: "pool1"
}
layer { #卷积层,同上
name: "conv2"
type: "Convolution"
bottom: "pool1"
top: "conv2"
param {
lr_mult: 1
}
param {
lr_mult: 2
}
convolution_param {
num_output: 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 { #非线性层,用insanity方法
name: "relu2"
type: "Insanity"
bottom: "pool2"
top: "pool2"
}
layer { #全连接层
name: "ip1"
type: "InnerProduct" #定义内积层,也称为全连接层
bottom: "pool2" #输入
top: "ip1" #输出
param {
lr_mult: 1
}
param {
lr_mult: 2
}
inner_product_param {
num_output: 500 #滤波器个数
weight_filler { #解释同上
type: "xavier"
}
bias_filler {
type: "constant"
}
}
}
layer { #非线性层,Insanity方法
name: "relu3"
type: "Insanity"
bottom: "ip1"
top: "ip1"
}
layer { #全连接层
name: "ip2"
type: "InnerProduct"
bottom: "ip1" #输入
top: "ip2" #输出
param {
lr_mult: 1 #参数学习率,和全局参数保持一致
}
param {
lr_mult: 2 #偏置学习率,是全局学习率的2倍
}
inner_product_param { #全连接参数
num_output: 10 #输出节点个数
weight_filler { #参数滤波类型
type: "xavier"
}
bias_filler { #偏置滤波类型,常量填充默认0
type: "constant"
}
}
}
layer { #分类准确率层,只在testing阶段有效
name: "accuracy"
type: "Accuracy"
bottom: "ip2" #输入iP2
bottom: "label" #对应标签输入
top: "accuracy" #输出
include {
phase: TEST #测试有效
}
}
layer { #损失层
name: "loss"
type: "SoftmaxWithLoss" #损失函数类型
bottom: "ip2" #输入
bottom: "label" #输入
top: "loss" #输出
}
# The train/test net protocol buffer definition
net: "examples/mnist/Mnist_demo_LeNet.prototxt" #网络协议,既用哪个网络结构
# test_iter specifies how many forward passes the test should carry out.
# In the case of MNIST, we have test batch size 100 and 100 test iterations,
# covering the full 10,000 testing images.
test_iter: 100 #预测阶段迭代次数为100,设置预测迭代次数为100可以覆盖全部的10000个测试集
# Carry out testing every 500 training iterations.
test_interval: 500 #测试频率,训练时,没迭代500次进行一次测试
# The base learning rate, momentum and the weight decay of the network.
base_lr: 0.01 #基础学习率
momentum: 0.9 #基础冲量
#solver_type: ADAGRAD
weight_decay: 0.0005 #基础权衰量
#weight_decay: 0.0005
# The learning rate policy
lr_policy: "inv" #学习速率的衰减策略
gamma: 0.0001
power: 0.75
# Display every 100 iterations
display: 100 #每100次在屏幕上打印log
# The maximum number of iterations
max_iter: 10000 #最大迭代次数
# snapshot intermediate results
snapshot: 5000 #每5000次打印一次快照,既模型保存
snapshot_prefix: "examples/mnist/lenet" #打印快照位置
# solver mode: CPU or GPU
solver_mode: GPU #设置CPU或者GPU
这里只做简单说明,更深的内容还需要查阅相关paper和基础知识。。。。